æ¨æ¥ã®ã ãããªãåã¿ä¼ã§ã¡ãã£ã¨è©±é¡ã«ãªã£ãã®ã§èª¿ã¹ã¦ã¿ã¾ããã
確ãã
Windowsã¹ãã¢ã¢ããªã§CoreTweet使ãæã«ãPINã³ã¼ã使ããã«èªè¨¼ããã®ã£ã¦ã©ããã£ãããããï¼
ã¿ãããªè©±ã ã£ãã¨æãã¾ã*1ã
WebAuthenticationBrokerã使ãã¨ç°¡åã«å®è£ ã§ãã
ã³ã¼ãã¯ãããªæãã
var apiKey = "{API Key}"; var apiSecret = "{API Secret}"; var callback = "http://127.0.0.1:64003/Account/ExternalLoginCallback"; var uriCallback = new Uri(callback); var oAuthSession = await OAuth.AuthorizeAsync(apiKey, apiSecret , callback); var webAuthenticationResult = await WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.None, oAuthSession.AuthorizeUri, uriCallback); if (webAuthenticationResult.ResponseStatus == WebAuthenticationStatus.Success) { //http://127.0.0.1:64003/Account/ExternalLoginCallback?oauth_token=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&oauth_verifier=YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY var oauthVerifier = webAuthenticationResult.ResponseData.Split('&').First(x => x.Contains("oauth_verifier")).Split('=')[1]; var token = await oAuthSession.GetTokensAsync(oauthVerifier); await token.Statuses.UpdateAsync(status => "ãã¹ã"); }
äºåæºå
äºåã« Twitter Application Management ã«ã¦ã¢ããªã±ã¼ã·ã§ã³ã®ç»é²ãã¦ãAPIãã¼çãåå¾ãã¦ããå¿ è¦ãããã¾ããããã®è¾ºã¯çç¥ãã¾ãã
èªè¨¼ç»é¢ã®è¡¨ç¤º
OAuthSessionã¤ã³ã¹ã¿ã³ã¹ãåå¾ããã®ã¯ãã¤ãã®æãã§ããã
WebAuthenticationBrokerã®AuthenticateAsyncã¡ã½ããã«èªè¨¼ç¨ã®URLã渡ãã¦å¼ã³åºãã¨ãä¸ã®æ§ãªTwitterã®èªè¨¼ç»é¢ã表示ããã¾ãã
ããã§ãã¢ããªã±ã¼ã·ã§ã³ã®ä½¿ç¨ã許å¯ãã¦ãããã°OKã§ãã
èªè¨¼å¾ã®å¦ç
èªè¨¼ã«æåãããã©ãã㯠webAuthenticationResult.ResponseStatus ã§ãããã¾ãã
æåãã¦ãã㨠webAuthenticationResult.ResponseData ã«ä»¥ä¸ã®æ§ãªURLï¼Twitterèªè¨¼å¾ã«ãªãã¤ã¬ã¯ããããURLï¼ãæ ¼ç´ããã¦ãã¾ãã®ã§ãoauth_verifierã®å¤ãã©ãã«ããã¦åå¾ãã¾ã*2ã
http://127.0.0.1:64003/Account/ExternalLoginCallback?oauth_token=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&oauth_verifier=YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
ãã¼ã¯ã³ã®åå¾
oauth_verifierã®å¤ãOAuthSessionã¤ã³ã¹ã¿ã³ã¹ã®GetTokensAsyncã¡ã½ããã«æ¸¡ãã¨ããã¼ã¯ã³ãåå¾ã§ãã¾ãã
ææ
WebAuthenticationBroker便å©ã§ããï¼
å®ã¯ãWindowsã¹ãã¢ã¢ããªä½ã£ããã¨ãªãï¼ããã¸ã§ã¯ãä½ã£ãäºãããéå»10åããªããããï¼ã®ã§ããããããã§ã¡ãã£ã¨è§¦ãããã¨ãã§ãã¾ããã
èãã¦ãããã ãããªãããããããã¨ãã