I'm looking for a function to download N images from Twitter with certain text in the tweet. Is there a better way to perform this search than this naive code:

twitter = ServiceConnect["Twitter", "New"];
w = twitter["TweetSearch", "Query" -> "Whotel", MaxItems -> 25, 
   "Elements" -> "Images"];
twitter["GetTweet", "TweetID" -> #, "Elements" -> "Images"] & /@ 
 Normal@w[All, "ID"]

which is wasteful and slow and doesn't find N images:

enter image description here

Clearly performing a "TweetSearch" request with "Elements" -> "Images" doesn't search for only tweets with images.

  • $\begingroup$ Twitter service in mathematica do not search tweets based on images, it searches/gets tweets based on query string. The content of the result may or may not contain Images. That is why you are seeing {} for tweets that has no images associated with them. Another thing there is no parameter called "Element" for "TweetSearch" request. $\endgroup$ – dsingh Dec 20 '16 at 22:23
  • 2
    $\begingroup$ You can improve the probability of getting tweets (with images) by modifying your query as " w = twitter["TweetSearch", "Query" -> "Whotel filter:images", MaxItems -> 25]" and then use 'GetTweet' on the results. More on this can be looked at "dev.twitter.com/rest/public/search". $\endgroup$ – dsingh Dec 20 '16 at 23:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.