Oauth2 / Xamarin-Google显示其主页

问题描述

我试图通过Google获取用户名邮件地址。但是,在用户登录后,Google会打开Goog​​le Hompepage,并且不会向应用返回任何内容

为什么会这样,我该如何解决

using Xamarin.Auth;

namespace test.Services
{
    public class AuthenticationState
    {
    public static OAuth2Authenticator Authenticator;
}

public static class AuthConstants
{
    public static string AppName = "test";


    public static string GoogleClientId          = @"396035829574-7qh2vrbindbm.....apps.googleusercontent.com";
    public static string GoogleClientSecret   = @"r8lqPTr5D....";
    public static string GoogleAuthorizeUrl   = @"https://accounts.google.com/o/oauth2/auth";
    //public static string GoogleAccesstokenUrl = @"https://accounts.google.com/o/oauth2/token";
    public static string GoogleAccesstokenUrl = @"https://www.googleapis.com/oauth2/v4/token";

    public static string GoogleAndroidRedirectUrl = @"com.googleusercontent.apps.396035829574-7qh2vrbin..:/oauth2redirect";

    public static string GoogleScope = @"https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile";
    //public static string GoogleScope = @"email";
    }
}

auth = new OAuth2Authenticator(AuthConstants.GoogleClientId,string.Empty,AuthConstants.GoogleScope,new Uri(AuthConstants.GoogleAuthorizeUrl),new Uri(AuthConstants.GoogleAndroidRedirectUrl),new Uri(AuthConstants.GoogleAccesstokenUrl),null,true);

authPresenter.Completed += (sender,args) => {
    var request = new OAuth2Request("GET",new Uri("https://www.googleapis.com/oauth2/v2/userinfo"),args.Account);
    Task<Response> googleResponse = request.GetResponseAsync();
    googleResponse.Wait();
    var googleUser = JsonValue.Parse(googleResponse.Result.GetResponseText());
    userInfo.Add("username",googleUser["email"]);
    userInfo.Add("password",googleUser["id"]);
};

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)