stackoverflowuser95
stackoverflowuser95

Reputation: 2070

Connect to Twitter given already have token?

I have looked at all the Python Twitter API wrappers that I could find on Bitbucket, Github and PyPi, but have been unable to find one which allows you to connect to Twitter if you already have the authentication token.

I am aware that I can generate the authentication token using an OAuth token, OAuth token secret, Twitter Token and Twitter Secret; but I would like to skip that processing + not prompt users who already have accounts.

The tweepy library seems popular; but lacks documentation...

Would someone be able to show me a tweet postage which uses Tweepy (or any other Python Twitter library) that uses only the authentication token?

EDIT: I ended up getting to work right with Twython.

Upvotes: 0

Views: 167

Answers (1)

Ifthikhan
Ifthikhan

Reputation: 1474

You have to store the access token and secret returned by the provider after authentication and use them in the subsequent requests to read or write. I have been using rauth (https://github.com/litl/rauth) and highly recommend it.


EDIT

Assuming you have already have a valid access token and a secret you can create a service object and read or write data using the twitter API (skipping the authentication steps). I have included the necessary steps from the rauth documentation below:

twitter = OAuth1Service(
    name='twitter',
    consumer_key='YOUR_CONSUMER_KEY',
    consumer_secret='YOUR_CONSUMER_SECRET',
    request_token_url='https://api.twitter.com/oauth/request_token',
    access_token_url='https://api.twitter.com/oauth/access_token',
    authorize_url='https://api.twitter.com/oauth/authorize',
    header_auth=True)

params = {'include_rts': 1,  # Include retweets
          'count': 10}       # 10 tweets

response = twitter.get('https://api.twitter.com/1/statuses/home_timeline.json',
                       params=params,
                       access_token=access_token,
                       access_token_secret=access_token_secret,
                       header_auth=True)

Upvotes: 2

Related Questions