0

我对 ipython 和 twython 的概念很陌生。但是我想使用 twitter.search 查询检索一些数据。但是当我使用它时,它给了我以下错误

In [3]: search_results = twitter.search(q="#india", rpp="50")
---------------------------------------------------------------------------


TwythonError                              Traceback (most recent call last)
/home/vishal/<ipython-input-3-241f789b11cc> in <module>()
----> 1 search_results = twitter.search(q="#india", rpp="50")

/usr/local/lib/python2.7/dist-packages/twython-2.5.5-py2.7.egg/twython/twython.pyc in search(self, **kwargs)
    365         """
    366 
--> 367         return self.get('https://api.twitter.com/1.1/search/tweets.json', params=kwargs)
    368 
    369     def searchGen(self, search_query, **kwargs):

/usr/local/lib/python2.7/dist-packages/twython-2.5.5-py2.7.egg/twython/twython.pyc in get(self, endpoint, params, version)
    236 
    237     def get(self, endpoint, params=None, version='1.1'):
--> 238         return self.request(endpoint, params=params, version=version)
    239 
    240     def post(self, endpoint, params=None, files=None, version='1.1'):

/usr/local/lib/python2.7/dist-packages/twython-2.5.5-py2.7.egg/twython/twython.pyc in request(self, endpoint, method, params, files, version)
    231             url = '%s/%s.json' % (self.api_url % version, endpoint)
    232 
--> 233         content = self._request(url, method=method, params=params, files=files, api_call=url)
    234 
    235         return content

/usr/local/lib/python2.7/dist-packages/twython-2.5.5-py2.7.egg/twython/twython.pyc in _request(self, url, method, params, files, api_call)
    208             raise exceptionType(error_msg,
    209                                 error_code=response.status_code,
--> 210                                 retry_after=response.headers.get('retry-after'))
    211 
    212         # if we have a json error here, then it's not an official TwitterAPI error


TwythonError: 'Bad Request: The request was invalid. An accompanying error message will explain why. This is the status code will be returned during rate limiting. -- An error occurred processing your request

可能是什么问题。是否需要身份验证

谢谢

4

2 回答 2

2

然而,Twitter API v1 搜索不需要身份验证;Twitter 搜索 API 现在需要在 v1.1 中进行身份验证。(https://dev.twitter.com/docs/api/1.1/get/search/tweets

感谢您使用Twython

于 2013-04-23T23:14:45.667 回答
0

对我来说,这段代码有效:

from twython import Twython

twitter = Twython()
search_results = twitter.search(q="#india", rpp="50")
for tweet in search_results["results"]:
    print "Tweet from@%s Date: %s" % (tweet['from_user'].encode('utf-8'),tweet['created_at'])
    print tweet['text'].encode('utf-8'),"\n"
于 2013-01-10T19:38:31.663 回答