Skip to content

Instantly share code, notes, and snippets.

@imjohsep
Created October 30, 2013 22:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imjohsep/7241442 to your computer and use it in GitHub Desktop.
Save imjohsep/7241442 to your computer and use it in GitHub Desktop.
Twitter Oauth with Tweepy and ConfigParser
import ConfigParser
import tweepy
Twitter Oauth with ConfigParseConfig = ConfigParser.ConfigParser()
Config.read('config.ini')
def ConfigSectionMap(section):
dict1 = {}
options = Config.options(section)
for option in options:
try:
dict1[option] = Config.get(section, option)
if dict1[option] == -1:
DebugPrint("skip: %s" % option)
except:
print("exception on %s!" % option)
dict1[option] = None
return dict1
def oauth():
consumer_key = ConfigSectionMap('Oauth')['key']
consumer_secret = ConfigSectionMap('Oauth')['secret']
access_token = ConfigSectionMap('Token')['access_token']
access_token_secret = ConfigSectionMap('Token')['access_token_secret']
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
user = api.get_user()
print user.screen_name
def main():
oauth()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment