【发布时间】:2015-07-10 04:14:49
【问题描述】:
我使用下面的代码来获取访问令牌但是它抛出方法没有实现。如何获取访问令牌请帮我在 windows phone 8.1 通用应用程序中获取访问令牌
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)
{
}
}
【问题讨论】:
标签: c# windows-runtime windows-phone-8.1