Skip to content

Instantly share code, notes, and snippets.

Created October 18, 2018 15:18
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Twitter APIからtokenを取得するためのPython3のスクリプト。Consumer API key及びConsumer API secret keyはJSONファイルから読み込む。
#!/usr/bin/env python3
import os
from twitter import *
import json
consumer_key_file = "consumer_key_file.json"
with open(consumer_key_file) as infile:
text =
keypair = json.loads(text)
#consumer key, consumer secret key from
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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment