birdy.twitter.TwitterApiError:无法解码JSON响应

时间:2018-02-13 14:47:04

标签: python api twitter oauth-2.0

我正在尝试使用OAuth 2.0使用Streaming API分析Twitter实时数据

我正在使用birdy twitter API客户端link

from birdy.twitter import AppClient,StreamResponse

CONSUMER_KEY = 'B....c'
CONSUMER_SECRET = 'l....A'

client = AppClient(CONSUMER_KEY, CONSUMER_SECRET)
access_token = client.get_access_token()
resource = client.stream.statuses.filter.post(track='twitter')
for data in resource.stream():
       print data

执行时,我收到以下错误

  

追踪(最近一次呼叫最后一次):

     

文件“webapp / streams.py”,第23行,in       resource = client.stream.statuses.filter.post(track ='twitter')     文件“/home/ravi/PycharmProjects/twitter-livestream/venv/local/lib/python2.7/site-packages/birdy/twitter.py”,第86行,在帖子中       return self._client.request('POST',self._path,** params)

     

文件“/home/ravi/PycharmProjects/twitter-livestream/venv/local/lib/python2.7/site-packages/birdy/twitter.py”,第167行,请求中       return self.handle_response(方法,响应)

     

文件“/home/ravi/PycharmProjects/twitter-livestream/venv/local/lib/python2.7/site-packages/birdy/twitter.py”,第189行,在handle_response中       提出TwitterApiError('无法解码JSON响应。',response = response,request_method = method)

     

birdy.twitter.TwitterApiError:无法解码JSON响应。 (POST https://stream.twitter.com/1.1/statuses/filter.json

先谢谢... :)

1 个答案:

答案 0 :(得分:0)

(我正在使用Python 3)

以下为我工作......

from birdy.twitter import StreamClient

# insert your consumer key/secret, access token/secret
client = StreamClient("xx",
                    "xx",
                    "xx",
                    "xx")

response = client.stream.statuses.filter.post(track='twitter')
for data in response.stream():
    print (data)