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)
{
}
}