Created
October 18, 2018 22:08
-
-
Save pandanote-info/2119131833021f6d54c234eb2374cf25 to your computer and use it in GitHub Desktop.
Twitter APIからタイムラインを取得し、その結果を標準出力に出力するPython3のプログラム例。
This file contains 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 python3 | |
import os | |
from twitter import * | |
import json | |
consumer_key_file = "consumer_key_file.json" | |
CONSUMER_KEY = "" | |
CONSUMER_SECRET="" | |
with open(consumer_key_file) as infile: | |
text = infile.read() | |
keypair = json.loads(text) | |
#consumer key, consumer secret key from https://apps.twitter.com/ | |
CONSUMER_KEY = keypair["consumer_key"] | |
CONSUMER_SECRET= keypair["consumer_key_secret"] | |
MY_TWITTER_CREDS = "pandanote_publisher_credentials.txt" | |
if not os.path.exists(MY_TWITTER_CREDS): | |
oauth_dance("Pandanote publisher", CONSUMER_KEY, CONSUMER_SECRET, MY_TWITTER_CREDS) | |
oauth_token, oauth_secret = read_token_file(MY_TWITTER_CREDS) | |
twitter = Twitter(auth=OAuth(oauth_token, oauth_secret, CONSUMER_KEY, CONSUMER_SECRET)) | |
print(twitter.statuses.home_timeline()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment