codebird-js icon indicating copy to clipboard operation
codebird-js copied to clipboard

Uploading Media: Code 220

Open superjoefly opened this issue 7 years ago • 1 comments

I've been trying to upload media (small images) to Twitter, but the "media_upload" call has been producing an error: (code: 220, message: "Your credentials do not allow access to this resource.)

This is the code I'm using to convert the image to base64:

encodeImageFileAsURL(e) {
      let input = event.target;
      if (input.files && input.files[0]) {
        let file = input.files[0];
        let reader = new FileReader()
        reader.onloadend = function() {
          window.store.state.selectedImage = reader.result.substr(reader.result.indexOf(',') + 1);
        }
        reader.readAsDataURL(file);
      }
   }

And this is the code I've been using for the call:

    var params = {
      "media_data": state.selectedImage
    };

    cb.__call(
      "media_upload",
      params,
      function(reply, rate, err) {
          console.log(reply.media_id_string);     // => undefined
      }
    )

Any suggestions on how to approach this?

Sidenote: all my other calls to the twitter api are working.

Thanks for your help :-)

superjoefly avatar Aug 25 '17 07:08 superjoefly

@superjoefly Are you accessing media_upload using application-only auth or from within a user context on full OAuth with access token?

mynetx avatar Sep 15 '18 12:09 mynetx