skip to Main Content

everything is in the title.

I’m using the twitter search API in Python to search for specific tweets and I’d like to find ONLY the ones that contains pictures / photos.

I tried a few things such as getting the URL of the ‘external’ media which partially works but when a picture is posted directly from twitter there is no URL to get, it’s like a tweet without pictures.

I found this topic but it is in Ajax and I have no idea how to do the same thing is Python.

2

Answers


  1. Chosen as BEST ANSWER

    Thanks for the recommendations, I somehow managed to do what I wanted. Basically I was using the search tweets functionnality to get tweets but then I had no idea how to check if the tweet had a media. It seems like some documentation pages of the twitter API website are not up to date.

    There is indeed a "media" parameter (nothing about that on the API website), which is used when someone post a tweet with pictures directly from twitter. If the picture is shared in any other way than uploaded to twitter, the media parameter of the tweet is empty ... actually the paramater itself is not even displayed BUT the "urls" parameter contains a bunch of usefull information including the website where the pictures are added from.

    So what I did is : Getting tweets, looping through them to check if each one of them have a media parameter (picture(s) uploaded to twitter directly), if they do not have a media I check the urls parameter to see if the website is "accepted", In my case I didn't wanted any tweets includding Youtube and Instagram links.

    Then I can do whatever I want with all those tweets that match my conditions.


  2. Can you build a custom query from the TwitterSearch API in Python and execute it?

    If yes you could use “filter:images” as a parameter of the query to get only those with images, like this query, but note that it uses the php-api

    Or maybe you could use “filter:media” (get all tweets with media) combined with “-filter:video” (remove those with videos), if I’m not wrong “filter:images” returns tweets that have a image URL

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search