PLhery / node-twitter-api-v2

Strongly typed, full-featured, light, versatile yet powerful Twitter API v1.1 and v2 client for Node.js.
https://www.npmjs.com/package/twitter-api-v2
Apache License 2.0
1.24k stars 174 forks source link

[bug] Error when uploading GIFs #519

Open anaisberg opened 4 months ago

anaisberg commented 4 months ago

Describe the bug When trying to upload GIFs using the uploadMedia endpoint, I get an {"code":1,"name":"InvalidMedia"} error. Uploading images works well with png/jpg however.

To Reproduce Please indicate all steps that lead to this bug:

  1. Request client setup (login method, OAuth2 scopes if applicable...)
 import { TwitterApi } from 'twitter-api-v2';
 const client = new TwitterApi({
    appKey: XXXX,
    appSecret: XXXX,
    accessToken: XXXX,
    accessSecret: XXXX,
 });
  1. Endpoint used or code example of what's happening wrong
const mediaId = await client.v1.uploadMedia('./paris.gif', {
  mimeType: 'image/gif,
});
  1. Error stack trace, and if possible, error content (err.toJSON() when err is the caught error; take care of removing authentication HTTP headers)
    {
    "media_id":1763597253904670720,
    "media_id_string":"1763597253904670720",
    "media_key":"16_1763597253904670720",
    "size":384852,
    "processing_info":{
    "state":"failed",
    "progress_percent":99,
    "error": {"code":1,"name":"InvalidMedia"}
    }
    } 

Expected behavior The gifs is uploaded, state success

Version

Additional context

After looking into the code, I realized that the media_category computed for gifs is TweetGif (in the getMediaCategoryByMime function), where in the API documentation, it is specified that the media_category should be tweet_gif