简体   繁体   English

twitterAPI python错误:JSON对象无法解码

[英]twitterAPI python error : No JSON object could be decoded

I'm using twitterAPI python wrapper https://github.com/geduldig/TwitterAPI 我正在使用twitterAPI python包装器https://github.com/geduldig/TwitterAPI

    CONSUMER_KEY = ''
    CONSUMER_SECRET = ''
    ACCESS_TOKEN_KEY = ''
    ACCESS_TOKEN_SECRET = ''

    api = TwitterAPI(
                    CONSUMER_KEY,
                    CONSUMER_SECRET,
                    ACCESS_TOKEN_KEY,
                    ACCESS_TOKEN_SECRET,
                    # auth_type='oAuth1',
                    # proxy_url=None
    )
    r = api.request('account/verify_credentials')
    print(r.text)

This is working fine I'm getting proper response so I tried to use filter api of twitter 'statuses/filter' https://dev.twitter.com/docs/api/1.1/post/statuses/filter with 'follow' parameter 这是工作的罚款,我得不到应有的回应,所以我试图用Twitter的状态/过滤器“的过滤器API https://dev.twitter.com/docs/api/1.1/post/statuses/filter与“关注”参数

lst = api.request('statuses/filter', {'follow': 'some_user_id'}) #user_id = 123456789, some 9 digit number lst = api.request('statuses/filter', {'follow': 'some_user_id'}) #user_id = 123456789,约9位数字

I print type of this object print(type(lst)) and I get <class 'TwitterAPI.TwitterAPI.TwitterResponse'> 我打印此对象的print(type(lst))并得到<class 'TwitterAPI.TwitterAPI.TwitterResponse'>

but when I try to access methods of this class it gives me error No JSON object could be decoded you can find all the methods of this class here http://twitterapi.readthedocs.org/en/latest/ 但是,当我尝试访问此类的方法时,出现错误消息No JSON object could be decoded您可以在此处找到此类的所有方法http://twitterapi.readthedocs.org/en/latest/

I have tried all 4 methods print(lst.get_iterator()) ,... , print(lst.text) but same error. 我已经尝试了所有4种方法print(lst.get_iterator()) ,..., print(lst.text)但是有相同的错误。
Any help will be appreciated. 任何帮助将不胜感激。

Once you get a TwitterResponse object with 一旦得到一个TwitterResponse对象,

lst = api.request('statuses/filter', {'follow': 'some_user_id'})

you can iterate the returned stream of statuses using 您可以使用以下方法迭代返回的状态流

for item in lst:
  print(item['text'])

You can also get the HTTP status code using 您还可以使用以下命令获取HTTP状态代码

print(lst.status_code)

However, print(lst.text) will not work because statuses/filter uses a continuous streaming connection. 但是,由于状态/过滤器使用连续的流连接,所以print(lst.text)将不起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM