Get Tweets with Pictures using twitter search api

20,638

Solution 1

There is no specific way to specify that I need only photos or videos but you can filter the results based on filter:links or filter:images or filter:videos in your query along with include_entities=true.

For Example: To get the tweets that contain links since 2012-01-31, you query should have include_entities parameter as well as filter:links as shown as follows:

https://search.twitter.com/search.json?q=from%3Agoogle%20since%3A2012-01-31%20filter%3Alinks&include_entities=true"

As your need is to filter your tweets based on images/photos, I think you should use filter:images.

An example of your case would look like:

https://search.twitter.com/search.json?q=from%3Agoogle%20since%3A2012-01-31%20filter%3Aimages&include_entities=true"

Hope this helps.

Solution 2

With Latest twitter API I couldn't get filters work and I couldn't find either any explanation in their docs. Althought you can get all the tweets and then parse only the media ones. You can fire this if inside your parsing script:

if(this.entities.media != null){
  //Parse the tweet
}

This is not the best solution but the worst part comes to twitter who's giving you more information and using more of its own resources.

Share:
20,638
Hemant P
Author by

Hemant P

Updated on July 09, 2022

Comments

  • Hemant P
    Hemant P almost 2 years

    Is it possible to get tweets which contain photos? I am currently using twitter search api and getting all the tweets having entity details by setting include_entities=true. I see picture details under media object but is there anyway to filter and get tweets objects which just have these media items. Or is there anyway in Twitter4j to do this query?

  • Hemant P
    Hemant P over 11 years
    Search using filter:images doesn't return any results. The sample google url in sample above does not return tweets containing images even though there are tweets from google which have images. Am i missing something? I removed filter:images and it returns tweets, some of which have images.
  • Hemant P
    Hemant P over 11 years
    ok i figured it out. filter:images only returns images that are not uploaded directly thru twitter a.k.a images having url starting from pic.twitter.com. so i modified my query to following: 'search.twitter.com/…'
  • Kiquenet
    Kiquenet over 9 years
    Works using latest Twitter API ?
  • Bảo Nam
    Bảo Nam about 9 years
    filter=images&include_entities=true works like a charm, thank you