AIR/ActionScript3ã§Twitterã®OAuthãããããã®å¿ è¦æä½é
OAuthé¢åãããã®ã§ãAIR/AS3ã§æä½éèªè¨¼éãããã«ãªãã¾ã§ã®ã¡ã¢ã
æºå
Twitterã«ã¢ããªã±ã¼ã·ã§ã³ç»é²ãhttps://twitter.com/apps
OAuthã©ã¤ãã©ãªãiotashanæ°ä½ã®ãã®ãå©ç¨ã
http://code.google.com/p/oauth-as3/
ã©ã¤ãã©ãªã使ãããOAuthãï¼ããå©ãã¨æ»ãã¾ãã
ãããã¨
1. RequestTokenåå¾2. PINã³ã¼ãåå¾
3. AccessTokenåå¾
1.RequestTokenåå¾
OAuthConsumerãªãã¸ã§ã¯ããçæãkeyã«Twitterããåå¾ããConsumer keyã¨ã
secretã«åããåå¾ããConsumer secretãè¨å®ããã
OAuthRequestãªãã¸ã§ã¯ããã
RequestTokenã®URL(http://twitter.com/oauth/request_token)ã¨ã
OAuthConsumerãªãã¸ã§ã¯ããã³ã³ã¹ãã©ã¯ã¿å¼æ°ã«æ¸¡ãã¦çæã
HTTPMethodã¯GETã§è¯ãã
ããã«ãOAuthRequestãªãã¸ã§ã¯ããããbuildRequestã¡ã½ãããã³ã¼ã«ãã¦ã
URLãåå¾ããã
å¼æ°ã«ã¯new OAuthSignatureMethod_HMAC_SHA1()ã渡ãã¦ããã
ãã®URLãHTTPServiceãªã©ã使ã£ã¦HTTP GETãæããã
æåããã¨ãoauth_tokenã¨oauth_secretãæ»ã£ã¦ããã
oauth_tokenãRequestToken Keyã§ãoauth_secretãRequestToken secretã
ç°¡åãªèª¬æã
ããã§ã¯ãRequestTokenã¨ãããã®ãTwitterããåå¾ãã¾ãã
ç»é²ã¢ããªã±ã¼ã·ã§ã³ãèå¥ããConsumer keyã渡ããã¨ãã¡ã¤ã³ãªã®ã§ããã
ãã Consumer keyã渡ãã®ã§ã¯ãªããConsumer secretãå©ç¨ãã¦ã
ããã·ã¥åï¼SHA1ï¼ãããã®ã渡ãã¾ãã
âã¦ã½æ¸ãã¾ãããConsumer keyã¯ãã®ã¾ã¾é£ãã§ããã¾ãã
ããã·ã¥åã¯ã·ã°ããã£(oauth_signature)ãä½æããæã«è¡ãã¾ãã
ãã®ä»ãtimestampãnonceã¨ãã£ãæååãå¿
è¦ãªã®ã§ãããbuildRequestãèªåçæãã¾ãã
ã¡ãªã¿ã«ãOAuthã®è¦æ ¼ã§ã¯ãsignatureãå¹³æã§æ¸¡ãã¦ãè¯ããã¨ã«ãªã£ã¦ãã¾ããã
Twitterã¯å¹³æã§ã®éä¿¡ãèªãã¦ãã¾ããã
2.PINã³ã¼ãåå¾
1.ã§åå¾ããRequestToken keyããã©ã¡ã¼ã¿ã¨ãã¦ãAuthorize URLã«ã¢ã¯ã»ã¹ã
ç´ã«æ¸ãã¨ã
https://twitter.com/oauth/authorize?oauth_token=åå¾ããRequestToken Key
ãã®URLã¯navigateToURLãªã©ã使ã£ã¦ãã©ã¦ã¶ãèµ·åãã¾ãã
ã¦ã¼ã¶ã«å©ç¨è¨±å¯ãæ±ããç»é¢ã«ç§»ãã¾ãã
ã¦ã¼ã¶ã許å¯ãåºãã¨ã7æ¡ã®PINã³ã¼ãã表示ãããã®ã§ããããä¿åãã¾ãã
ãã®PINã³ã¼ãã¯oauth_verifierã¨ãã¦å¾ã§ä½¿ãã¾ãã
Webã¢ããªã®å ´åã¯oauth_callbackã¨ãããã©ã¡ã¿ãæå®ããã¨ã
æå®å
ã«ãªãã¤ã¬ã¯ããã¦ããã¾ããã
AIRãªã©ã®ãã¹ã¯ãããã®å ´åãä»ã®æ¹æ³ã§PINãä¿åããå¿
è¦ãããã¾ãã
è¥å¹²é¢åã§ãã
3.AccessTokenåå¾
ãããåä»ãªã®ã§ãã³ã¼ã風ã«è¨è¿°ã
var consumer:OAuthConsumer = new OAuthConsumer(Consumer key, Consumer secret);
var reqToken:OAuthToken = new OAuthToken(Request token key, Request token secret);
var request:OAuthRequest = new OAuthRequest("GET", access_token url, {oauth_verifier: PIN, oauth_version: "1.0"}, consumer, reqToken);
var url:String = request.buildRequest(new OAuthSignatureMethod_HMAC_SHA1());
ãã®urlãHTTPServiceãªã©ã§HTTP GETãã¾ãã
æ»ãå¤ã®tokenã¨secretããæ°¸ä¹
ä¿åçã®Access Tokenã§ãã
AccessTokenã®åå¾ã§ãã£ã¦ãããã¨ã¯ããªããããã¥ããã®ã§ã
çæããurlãtraceãªã©ã§è¦³å¯ããã¨ããã¨æãã¾ãã
ãã®ãã¼ã¸ãç¹ã«åèã«ãªããã¨ã
Twitter API ã OAuth ã§èªè¨¼ããã¹ã¯ãªããã 0 ããæ¸ãã¦ã¿ã
http://techno-st.net/2009/11/26/twitter-api-oauth-0.html