Python+Twitter API:タイムラインの取得

import json, config #標準のjsonモジュールとconfig.pyの読み込み
from requests_oauthlib import OAuth1Session #OAuthのライブラリの読み込み
from control_wordpress_oembed import post_contents

CK = config.CONSUMER_KEY
CS = config.CONSUMER_SECRET
AT = config.ACCESS_TOKEN
ATS = config.ACCESS_TOKEN_SECRET

twitter = OAuth1Session(CK, CS, AT, ATS) #認証処理

url = 'https://publish.twitter.com/oembed'
url_tl = 'https://api.twitter.com/1.1/statuses/user_timeline.json'

params_tl = {'screen_name':'345__chan','count':'5'}

req_tl = twitter.get(url_tl ,params = params_tl)

post_list = []
id_list = []

if req_tl.status_code == 200:
        dic_tl = json.loads(req_tl.text)
        for a in dic_tl:
                id_str = str(a['id'])
                twitter_url = 'https://twitter.com/'+'345__chan/'+'status/'+id_str
                print(twitter_url)
                params = {'url' :twitter_url, 'hide_media' : False}
                req = twitter.get(url, params = params)
                dic = json.loads(req.text)
                html = dic['html']
                post_list.append(html)

else:
        print("ERROR: %d" % req.status_code)

post_contents(post_list)

python, twitter api

Posted by iser