twitter-lite
twitter-lite copied to clipboard
Authentication error on media/upload
Hi!,
I was trying to upload an image and post a twit for a quite long and I was getting error code 32 (authentication issue), and I wasn't able to figure out why I was getting the error until I read some issue in the repo about encoding and tried with the same API but uploading the image in base 64.
The code that wasn't working is:
uploadImage(path: string) {
const data = fs.readFileSync(path);
return this.mediaClient.post('media/upload', {
media: data,
}).then((media) => {
fs.unlink(path, () => {});
return media;
});
}
And I'm getting this error:
{ errors: [ { code: 32, message: 'Could not authenticate you.' } ] }
But if I encode the image with base64:
uploadImage(path: string) {
const data = fs.readFileSync(path);
return this.mediaClient.post('media/upload', {
media_data: Buffer.from(data).toString('base64')
}).then((media) => {
fs.unlink(path, () => {});
return media;
});
}
Everything works fine, could be some issue with the encoding? Or I'm missing something?
man... your issue saved me. I'm having the same problem
me too