Windows phone 8.1 如何使用windows phone 8.1应用程序中的代码获取Google API访问代码?

Windows phone 8.1 如何使用windows phone 8.1应用程序中的代码获取Google API访问代码?,windows-phone-8.1,Windows Phone 8.1,我是Windows phone应用程序开发新手 我已经在谷歌开发者控制台中创建了我的应用程序。 从我的windows phone应用程序中,我使用“webview”呈现Google登录页面,成功登录后,我得到了如下代码:4/akd……。 有人能告诉我如何第一次使用“代码”访问代码吗 我尝试了以下方法: public void GetProfileDetail(string code) { StringBuilder authLink = new StringBuilder();

我是Windows phone应用程序开发新手

我已经在谷歌开发者控制台中创建了我的应用程序。 从我的windows phone应用程序中,我使用“webview”呈现Google登录页面,成功登录后,我得到了如下代码:
4/akd……。

有人能告诉我如何第一次使用“代码”访问代码吗

我尝试了以下方法:

public void GetProfileDetail(string code) 
{
    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}", clientId);
    authLink.AppendFormat("&client_secret={0}", clientSecret);
    authLink.AppendFormat("&redirect_uri={0}", redirect_url);
    authLink.Append("&grant_type=authorization_code");

    UTF8Encoding utfenc = new UTF8Encoding();
    byte[] bytes = utfenc.GetBytes(authLink.ToString());
    Stream os = null;


    try // send the post
    {
        //webRequest.ContentLength = bytes.Length; // Count bytes to send

        os = webRequest.GetRequestStreamAsync().Result;
        os.Write(bytes, 0, bytes.Length);        // Send it
    }
    catch (Exception ex)
    {

    }
}
但这给了我一个错误。让我知道下一步该做什么


提前感谢。

您正试图通过webview进行OAuth身份验证,但这不是推荐的方法

由于wp8.1,有一个
WebAuthenticationBroker
类,您可以使用它来启动与提供者的OAuth进程(就像您的例子中的Google)

可以在这里的MSDN上找到一个很好的详细示例