Oauth2/Xamarin-谷歌显示其主页
我试图通过谷歌获取用户的姓名和邮箱地址。但在用户登录后,Google会打开Google Hompe页面,不会向应用程序返回任何内容 为什么会发生这种情况?我该如何解决Oauth2/Xamarin-谷歌显示其主页,xamarin,xamarin.forms,oauth-2.0,google-authentication,Xamarin,Xamarin.forms,Oauth 2.0,Google Authentication,我试图通过谷歌获取用户的姓名和邮箱地址。但在用户登录后,Google会打开Google Hompe页面,不会向应用程序返回任何内容 为什么会发生这种情况?我该如何解决 using Xamarin.Auth; namespace test.Services { public class AuthenticationState { public static OAuth2Authenticator Authenticator; } public static class
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";
}
}
authPresenter.Completed+=(发件人,参数)=>{
var请求=新的OAuth2Request(“GET”),新的Uri(“https://www.googleapis.com/oauth2/v2/userinfo),空,参数帐户);
任务googleResponse=request.GetResponseAsync();
googleResponse.Wait();
var googleUser=JsonValue.Parse(googleResponse.Result.GetResponseText());
userInfo.Add(“用户名”,谷歌用户[“电子邮件]);
userInfo.Add(“密码”,googleUser[“id]”);
};
是否创建一个活动,然后添加IntentFilter
如本文所述,请参阅GoogleAuthInterceptor.cs
我测试您的已完成
,我可以获取信息。下面是跑步截图。
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"), null, 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"]);
};