Created
July 21, 2015 09:29
-
-
Save misodengaku/551f32e259e80f77a729 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| from requests_oauthlib import OAuth1Session | |
| import json | |
| CK = '' # Consumer Key | |
| CS = '' # Consumer Secret | |
| AT = '' # Access Token | |
| AS = '' | |
| # ツイート投稿用のURL | |
| #url = "https://api.twitter.com/1.1/statuses/update.json" | |
| url = "https://api.twitter.com/1.1/statuses/user_timeline.json" | |
| # ツイート本文 | |
| #params = {"status": "Hello, World!"} | |
| params = {'screen_name': 'habomaijiro', 'count': 200} | |
| # OAuth認証で POST method で投稿 | |
| twitter = OAuth1Session(CK, CS, AT, AS) | |
| req = twitter.get(url, params = params) | |
| # レスポンスを確認 | |
| if req.status_code == 200: | |
| # print ("OK") | |
| # print(req) | |
| json_str = ''.join(req) | |
| tw_obj = json.loads(json_str) | |
| print(json.dumps(tw_obj, sort_keys=True, indent=4)) | |
| # print(json.dumps(req, sort_keys=True, indent=4)) | |
| else: | |
| print ("Error: %d" % req.status_code) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment