1

I've setup a code in python to search for tweets using the oauth2 and urllib2 libraries only. (I'm not using any particular twitter library)

I'm able to search for tweets based on keywords. However, I'm getting zero number of tweets when I search for this particular keyword - "Jurgen%20Mayer-Hermann". (this is challenge because my ultimate goal is to search for this keyword only.

On the other hand when I search for the same thing online (twitter interface, I'm getting enough tweets). - https://twitter.com/search?q=Jurgen%20Mayer-Hermann&src=typd

Can someone please see if we can identify the issue?

The code is as follows:

def getfeed(mystr, tweetcount):
    url = "https://api.twitter.com/1.1/search/tweets.json?q=" + mystr + "&count=" + tweetcount
    parameters = []
    response = twitterreq(url, "GET", parameters)
    res = json.load(response)
    return res

search_str = "Jurgen Mayer-Hermann"
search_str = '%22'+search_str+'%22'
search = search_str.replace(" ","%20")
search = search.replace("#","%23")
tweetcount = str(50)
res = getfeed(search, tweetcount)

When I print the constructed url, I get

https://api.twitter.com/1.1/search/tweets.json?q=%22Jurgen%20Mayer-Hermann%22&count=50
dsauce
  • 592
  • 2
  • 14
  • 36
  • you can get your answer from here. http://stackoverflow.com/questions/12916539/simplest-php-example-for-retrieving-user-timeline-with-twitter-api-version-1-1 – Hardik Ranpariya Oct 31 '14 at 12:25

2 Answers2

0

I have actually never worked with the Twitter API, but it looks like the count parameter only applies to searches on timelines as a way to limit the amount of tweets per page of results. In other words, you use it with the GET statuses/home_timeline, GET statuses/mentions, and GET statuses/user_timeline endpoints.

Try without count and see what happens.

Vidya
  • 29,932
  • 7
  • 42
  • 70
  • Thanks for the response! (1) I'm not using any special twitter api. I'm only creating a search url and executing it to get the feed. (2) the code works for all the other keywords i tried instead of "Jurgen Mayer-Hermann" (3) i removed count as you mentioned and there is no change, still the same issue – dsauce Feb 26 '14 at 13:52
0

Please use urllib.urlencode to encode your query parameters, like so:

import urllib
query = urllib.urlencode({'q': '"Jurgen Mayer-Hermann"', count: 50})

This produces 'q=%22Jurgen+Mayer-Hermann%22&count=50'. Which might bring you more luck...

Menno
  • 1,133
  • 9
  • 14
  • Thanks @Menno for the reply. Unfortunately this is not working. I get the same error. Any other insights? – dsauce Feb 26 '14 at 15:36
  • i also checked that the code works for both "Jurgen" and "Mayer-Hermann" but not for "Jurgen Mayer-Hermann". Therefore, I need a way to make space separated search-able. – dsauce Feb 26 '14 at 15:42
  • It is weird... only thing I can otherwise think of is that the search api may return a subset of the tweets that Twitter search does? – Menno Feb 26 '14 at 20:30
  • I checked using twitter's console as well (https://dev.twitter.com/console) and resulted in zero tweets which indicates that the code is right. However, when use the same criterion to search manually on twitter.com it gives me a lot of tweets. Also, if I use topsy.com i get a lot of tweets. i'm frustrated why topsy is able to pull but i'm not. any thought/hints? – dsauce Feb 27 '14 at 04:37