I'm searching tweets through Twitter API with this endpoint
I'm testing with my own account. I tweeted a gif. But when I retrieve the json, I don't see the link of the attached media. It's automatically format in an url.
My aim is to store locally the images attached to tweets.
Yes, it is possible. If you are looking for animated GIFs, you need to look in the extended_entities
- here's an example:
"extended_entities": { "media": [ { "id": 626705406224658400, "id_str": "626705406224658432", "indices": [ 29, 51 ], "media_url": "http://pbs.twimg.com/tweet_video_thumb/CLKBPxzWcAAFhYz.png", "media_url_https": "https://pbs.twimg.com/tweet_video_thumb/CLKBPxzWcAAFhYz.png", "url": "http://t.co/psSAzQfcFu", "display_url": "pic.twitter.com/psSAzQfcFu", "expanded_url": "http://twitter.com/edent/status/626705407550078976/photo/1", "type": "animated_gif",
See! It tells you that there is an aGIF. Later on, you'll see the URL to directly download it.
"sizes": { "small": { "w": 14, "h": 14, "resize": "fit" }, "medium": { "w": 14, "h": 14, "resize": "fit" }, "thumb": { "w": 14, "h": 14, "resize": "crop" }, "large": { "w": 14, "h": 14, "resize": "fit" } }, "video_info": { "aspect_ratio": [ 1, 1 ], "variants": [ { "bitrate": 0, "content_type": "video/mp4", "url": "https://pbs.twimg.com/tweet_video/CLKBPxzWcAAFhYz.mp4" } ] } } ] },
Now, you can't download the GIF directly, but you can grab the video version of it.
If you want other imgage (JPG, PNG, etc) take a look for the "media_url_https"
field.