简体   繁体   中英

twitterAPI python error : No JSON object could be decoded

I'm using twitterAPI python wrapper 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

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

I print type of this object print(type(lst)) and I get <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/

I have tried all 4 methods print(lst.get_iterator()) ,... , print(lst.text) but same error.
Any help will be appreciated.

Once you get a TwitterResponse object with

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

print(lst.status_code)

However, print(lst.text) will not work because statuses/filter uses a continuous streaming connection.

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.

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