I'm trying to make a simple Twitter Bot that retweets users if their tweet contains a certain hashtag
So for my search url, I have the following: http://search.twitter.com/search.json?q=address&count=1
But whenever I run my program, I only get 1 tweet and its information. I'm confused as to why I only get 1 tweet and not 10. Even if I change up the value of the "count" parameter, I get 1 tweet.
And if I change the search url to replace "hashtags" with "q", I get a bunch of errors: http://search.twitter.com/search.json?hashtags=151milford&count=10
That line above gives me the following errors
File "C:\Users\Documents\pythonbot.py", line 16, in <module>
o = urllib2.urlopen(url) #open the url
File "C:\PYTHON27\LIB\urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout)
File "C:\PYTHON27\LIB\urllib2.py", line 406, in open
response = meth(req, response)
File "C:\PYTHON27\LIB\urllib2.py", line 519, in http_response
'http', request, response, code, msg, hdrs)
File "C:\PYTHON27\LIB\urllib2.py", line 444, in error
return self._call_chain(*args)
File "C:\PYTHON27\LIB\urllib2.py", line 378, in _call_chain
result = func(*args)
File "C:\PYTHON27\LIB\urllib2.py", line 527, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 403: Forbidden
I'm still trying to learn my way around the API so any tips would be awesome
Are you sure there are more tweets with that query?
Use that url in a browser, if you use for instance:
http://search.twitter.com/search.json?q=trending&count=10
You'll get 10 results.
That API for twitter will only get you relatively recent tweets, so if there are no recent tweets matching your query, you'll get nothing.
Take a look here https://dev.twitter.com/docs/api/1.1 to see what parameters are supported.
The errors you're getting are due to the fact that there is no "hashtags" parameter.
You are using an incorrect parameter for count. Check the documentation again .
Check out this URL that returns 5 items:
https://search.twitter.com/search.json?q=stackoverflow&rpp=5
You would use the parameter rpp
to control the number of results per-page , and the parameter page
to control the page-offset .
Also please move to the newer v1.1 API. You would find the link in @pcalcao post.
I think I found why my search isn't finding everything. Apparently Twitter doesn't index all of their tweets, so that is why I'm not getting everything in my search results.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.