Windows runtime 谷歌登录不';Don’别给我起名字和姓

Windows runtime 谷歌登录不';Don’别给我起名字和姓,windows-runtime,winrt-xaml,google-oauth,Windows Runtime,Winrt Xaml,Google Oauth,我需要从谷歌登录接收用户firstname和lastname。 这是我的代码: internal static string GoogleAppId = "XXXXXXXXXXXXX-scvpbtaoijuciinu1oneu7ijqtdvcpce.apps.googleusercontent.com"; internal static string GoogleAppSecret = "XXXXXXXXXXXUJuZNHhf6-8"; internal static U

我需要从谷歌登录接收用户firstnamelastname。 这是我的代码:

    internal static string GoogleAppId = "XXXXXXXXXXXXX-scvpbtaoijuciinu1oneu7ijqtdvcpce.apps.googleusercontent.com";
    internal static string GoogleAppSecret = "XXXXXXXXXXXUJuZNHhf6-8";
    internal static Uri GoogleStartUri = new Uri("https://accounts.google.com/o/oauth2/auth?client_id=" + Uri.EscapeDataString(GoogleAppId) + "&redirect_uri=" + Uri.EscapeDataString("urn:ietf:wg:oauth:2.0:oob") + "&response_type=code&scope=" + Uri.EscapeDataString("profile openid https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/plus.me email"));
    private string GoogleCallbackUrl = "urn:ietf:wg:oauth:2.0:oob";


    internal static Uri GoogleEndUri = new Uri("https://accounts.google.com/o/oauth2/approval?");

    public static void AuthenticateAndContinue()
    {
        StringBuilder googleUrl = new StringBuilder();
        googleUrl.Append("https://accounts.google.com/o/oauth2/auth?client_id=");
        googleUrl.Append(Uri.EscapeDataString(GoogleAppId));
        googleUrl.Append("&scope=openid%20email%20profile");
        googleUrl.Append("&redirect_uri=");
        googleUrl.Append(Uri.EscapeDataString(GoogleCallbackUrl));
        googleUrl.Append("&response_type=code");

        Uri startUri = new Uri(googleUrl.ToString());

        WebAuthenticationBroker.AuthenticateAndContinue(startUri, GoogleEndUri, null, WebAuthenticationOptions.UseTitle);
    }

    public static async Task<string> GetToken(string code)
    {
        var client = new HttpClient();
        var auth = await client.PostAsync("https://accounts.google.com/o/oauth2/token", new FormUrlEncodedContent(new[]
        {
            new KeyValuePair<string, string>("code", code),
            new KeyValuePair<string, string>("client_id",GoogleAppId),
            new KeyValuePair<string, string>("client_secret",GoogleAppSecret),
            new KeyValuePair<string, string>("grant_type","authorization_code"),
            new KeyValuePair<string, string>("redirect_uri","urn:ietf:wg:oauth:2.0:oob"),
            //new KeyValuePair<string, string>("redirect_uri","http://localhost")
        }));

        var data = await auth.Content.ReadAsStringAsync();
        var response = JsonConvert.DeserializeObject<TokenResponse>(data);
        System.Diagnostics.Debug.WriteLine(response.id_token);
        return response.id_token;
    }

    internal async void Continue(IContinuationActivatedEventArgs args)
        {
            if (args.Kind == ActivationKind.WebAuthenticationBrokerContinuation)
            {
                var data = ((WebAuthenticationBrokerContinuationEventArgs)args).WebAuthenticationResult.ResponseData.Split('&')[0];
                var code = data.Split('=')[1];
                System.Diagnostics.Debug.WriteLine($"code: {code}");
                var token = await GoogleManager.GetToken(code);

            }
        }

我做错了什么

您使用的端点用于获取有关令牌的信息。你应使用:

https://www.googleapis.com/oauth2/v3/userinfo?access_token={0}
https://www.googleapis.com/oauth2/v3/userinfo?access_token={0}