ttezel / twit

Twitter API Client for node (REST & Streaming API)
4.31k stars 568 forks source link

Fetch DM Images #404

Closed lshaf closed 6 years ago

lshaf commented 6 years ago

Hi,

Can you add function to fetch DM images from ton.twitter.com ? I've read every part of your code but there's no way to call request using custom url.

lshaf commented 6 years ago

Sorry, Just found it.

pthieu commented 5 years ago

@lshaf: can you point me to the location where you found this information?

lshaf commented 5 years ago

@pthieu I forgot about this one but I think I did it by using custom function.


    private downloadImage(url: string) {
        let time = Math.ceil((new Date()).getTime() / 1000);
        let twitter: any = this.Twitter;
        let config = twitter.config;
        let options = {
            url,
            headers: {
                "Accept": "*/*",
                "User-Agent": "biolbe-client"
            },
            oauth: {
                consumer_key: config.consumer_key,
                consumer_secret: config.consumer_secret,
                token_secret: config.access_token_secret,
                token: config.access_token,
                timestamp: String(time),
            }
        };

        return new Promise((resolve, reject) => {
            let bufferData: Buffer[] = [];
            request.get(options).on("data", (chunk: Buffer) => {
                bufferData.push(chunk);
            }).on("end", () => {
                resolve(Buffer.concat(bufferData));
            });
        });
    }

and I make that function based on script at this lib

pthieu commented 5 years ago

@lshaf ah thanks. I thought there was a simple convenience function you found, but looks like we have to figure it out manually.