twitter-lite icon indicating copy to clipboard operation
twitter-lite copied to clipboard

Authentication error on media/upload

Open fjdelarubia opened this issue 4 years ago • 2 comments

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?

fjdelarubia avatar May 01 '20 19:05 fjdelarubia

man... your issue saved me. I'm having the same problem

felpsio avatar May 28 '20 00:05 felpsio

me too

zeing avatar Jun 07 '20 12:06 zeing