Home>

I am trying to use the twitter API for practice as well, but
https://qiita.com/bakira/items/00743d10ec42993f85eb#comments
When I copy and paste the code on this site and try it for a while, nothing is displayed and it ends.
This code is to get and display the timeline of TWITTER

Applicable source code
python
import json
from requests_oauthlib import OAuth1Session
import key
CK = key.consumer_key
CS = key.consumer_secret
AT = key.token
ATS = key.token_secret
twitter = OAuth1Session(CK, CS, AT, ATS)
url = "https://api.twitter.com/1.1/statuses/user_timeline.json"
params ={'count':5}
res = twitter.get(url, params = params)
if res.status_code == 200:
    timelines = json.loads(res.text)
    for line in timelines:
        print(line['user']['name']+'::'+line['text'])
        print(line['created_at'])
        print('*******************************************')
else: #When communication is not successful
    print("Failed: %d" %res.status_code)
What I tried

I don't know anything because I am just beginning to use python and IDE as a student.

  • Answer # 1

    The result isres.status_code == 200When is true andfor line in timelines:I wonder if it's just that I haven't tweeted once, because inside is never executed.