python-twitpicでOAuth認証
twitterと連帯する画像投稿サービスであるtwitpic。そのAPIを利用するためにpython-twitpicというライブラリを利用することにしたのだがエラーで投稿できない。引数にAccess Token Secretが足りないのでは・・・?と思ったのは勘違いで、access_tokenはoauth_tokenとoauth_token_secretをurlencodeしたもの(分割前のAccess Token?)だった。別のTwitterClientで認証済みであることを想定しているためこのような仕様になっているらしい。
動作したコードは以下
import twitpic2 twitpic = twitpic2.TwitPicOAuthClient( consumer_key = "{consumer_key}", consumer_secret = "{consumer_secret}", service_key = "{twitpic_api_key}", access_token = "oauth_token={oauth_token}&oauth_token_secret={oauth_token_secret}", ) response = twitpic.create('upload', {'media': 'media.jpg', 'message': 'message' }) print response
My guess is in essence the app will send a one-time login on behalf of the user to Twitter most likely via a secure SSL encryption channel or similar and Twitter will return to the app an OAuth token to make API requests with on behalf of that user in the future. In my opinion this is still no different than storing an OAuth Token in a database that would give apps the same access as their Twitter username and password.
It is correct about this sample. However it is expected the python-twitpic library is used with other twitter client.
What I want to say in this article is “What string enter access_token argument?”
..Hi ..Im trying to wrap my head around OAuth Echo being in the Delegator .role of this diagram here ..Lets assume for a moment that the X-Verify-Credentials-Authorization.header that I get from the client consumer looks like this ..OAuth oauth timestamp 1279917460 oauth version 1.0 .oauth consumer key lookakey oauth token lookatoken .oauth signature lookasignature oauth nonce 8C8E6BE3-A897-8DE9-A15E-.FACB3C6B4E03 oauth signature method HMAC-SHA1 ..How would the http-header of the request from me D to twitter SP .look like? Your code shows you tacking on the oauth token to the.authorization header .
I suppose this code execute after authorized.
Because it is easier.
If you have
auth = ‘
oauth_consumer_key=”{consumer_key}”,
oauth_signature_method=”HMAC-SHA1″,
oauth_token=”{token}”,
oauth_timestamp=”{timestamp}”,
oauth_nonce=”{nonce}”,
oauth_version=”1.0″,
oauth_signature=”{signature}”
‘;
then, http-header is
request[“X-Verify-Credentials-Authorization”] = ‘realm=”http://api.twitter.com/”, ‘ + auth;
request[“X-Auth-Service-Provider”] = ‘https://api.twitter.com/1/account/verify_credentials.json’;
Please look at doc
http://dev.twitpic.com/docs/2/upload/
good luck!