I have an example from a test I run to make sure it works. The
"client" here is for hitting our API internally, but is equivalent to
something like urllib.
Here is creating an account with an OAuth header:
twitter_oauth_header =
twitter.export_oauth_credentials__3rd_party_oauth(p['oauth_token'],
p['oauth_token_secret'], consumer_key, consumer_secret)
response =
client.post( '/api/createTwitterAccount/',
{'twitter_username':twitter_username,
'twitter_oauth_header':twitter_oauth_header,
'user_agent':'some_test_app'} )
def export_oauth_credentials__3rd_party_oauth( oauth_token,
oauth_token_secret, _twitter_consumer_key, _twitter_consumer_secret ):
url = '
http://twitter.com/account/verify_credentials.json'
consumer = {'oauth_token': _twitter_consumer_key,
'oauth_token_secret': _twitter_consumer_secret}
token = {'oauth_token': oauth_token, 'oauth_token_secret':
oauth_token_secret }
oauth_request = OAuthRequest( url )
oauth_request.sign_request(OAuthSignatureMethod_HMAC_SHA1,
consumer, token=token)
page_request = urllib2.Request( url, headers={'Authorization' :
oauth_request.to_header()} )
return page_request.headers['Authorization']
I feel like I've posted this code on this list before. I clearly
should just make my tests public, so people can see what I'm doing to
make sure it works.
Also, check this out:
http://tipjoy.com/api/#authentication
The last app I built was tatatweet, which used passwords. The next one
will be closed source, much more expensive to use, and will utilize
OAuth. I hope to launch it within, say, 5 weeks.
Ivan
http://tipjoy.com