2015-07-10 34 views
0

我使用下面的代碼獲取訪問令牌,但未實現它的引發方法。如何獲得訪問令牌,請幫助我獲得訪問令牌中的Windows Phone 8.1應用程序的通用如何在Windows Phone 8.1中獲取Google Blogger訪問令牌通用應用程序

StringBuilder authLink = new StringBuilder(); 

      HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("https://accounts.google.com/o/oauth2/token"); 
      webRequest.ContentType = "application/x-www-form-urlencoded"; 
      webRequest.Method = "POST"; 
      authLink.AppendFormat("code={0}", "code"); 
      authLink.AppendFormat("&client_id={0}", "xxxxxxxxxx.apps.googleusercontent.com"); 
      authLink.AppendFormat("&client_secret={0}", "xxxxxxxxxx"); 
      authLink.AppendFormat("&redirect_uri={0}", "urn:ietf:wg:oauth:2.0:oob"); 
      authLink.Append("&grant_type=authorization_code"); 
      UTF8Encoding utfenc = new UTF8Encoding(); 
      byte[] bytes = utfenc.GetBytes(authLink.ToString()); 
      Stream os = null; 

      try // send the post 
      { 
       // Count bytes to send 
       os =await webRequest.GetRequestStreamAsync(); 
       os.Write(bytes, 0, bytes.Length);  // Send it 
      } 
      catch (Exception ex) 
      { 
      } 
      try // get the response 
      { 
       HttpWebResponse webResponse =(HttpWebResponse)await webRequest.GetResponseAsync(); 
       if (webResponse == null) 
       { 

       } 
       StreamReader sr = new StreamReader(webResponse.GetResponseStream()); 
       String Text = sr.ReadToEnd().Trim(); 
       //MessageBox.Show(sr.ReadToEnd().Trim()); 
      } 
      catch (Exception ex) 
      { 

      } 
     } 

回答

1

你需要檢查其官方的API文檔,搜索「谷歌的Blogger API」的說明。

我剛看了一下關於授權請求和識別您的應用程序的文檔,它也使用OAuth2.0協議,所以您需要使用WebAuthenticationBroker類連接到OAuth提供程序。

查看樣本即可開始:https://code.msdn.microsoft.com/windowsapps/Web-Authentication-d0485122

相關問題