【问题标题】:Google authentication using Xamarin.Auth使用 Xamarin.Auth 进行 Google 身份验证
【发布时间】:2014-09-11 00:16:54
【问题描述】:

我正在使用 Xamarin.Android 开发应用程序。

我需要启用 Facebook 和 Google 登录,并且我选择使用 Xamarin.Auth 组件。 我可以在 facebook 上使用它,但我在使用 Google 时遇到了一些问题。

这是我的代码:

        var auth = new OAuth2Authenticator (
            clientId: "myId.apps.googleusercontent.com",
            clientSecret: "mysecred",
            scope: "openid",
            authorizeUrl: new Uri ("https://accounts.google.com/o/oauth2/auth"),
            redirectUrl: new Uri ("myredirect:oob"),
            accessTokenUrl: new Uri ("https://accounts.google.com/o/oauth2/token"),
            getUsernameAsync: null
        ); 

        activity.StartActivity (auth.GetUI (activity));

        auth.Completed += (sender, e) => {
            Console.WriteLine (e.IsAuthenticated);
        };

谷歌活动是这样显示的吗,我可以插入我的用户名和密码。但是当我点击谷歌登录按钮时,我会收到这样的消息:

google auth 请将此代码开关复制到您的应用程序并将其粘贴到那里[代码]

我与该代码有什么关系?我只需要获取用户名/姓氏/电子邮件/id。

非常感谢!

【问题讨论】:

  • 你有解决这个问题的办法吗?
  • @user3471528,你得到解决方案了吗

标签: android oauth-2.0 xamarin xamarin.android


【解决方案1】:

以下步骤对我有用。

1.在谷歌开发者控制台中注册为 webapplication 而不是安装的 application(android)* 提供具有有效 url ("http://abcd.com/xyz.aspx") 的重定向 url 应在应用程序代码中使用。

2.认证完成后会返回access_token

3.使用access_token发起REST请求获取用户完整信息(https://www.googleapis.com/oauth2/v1/userinfo?access_token=" + accessTokenValue + ".)

4.反序列化json响应以获取对象中的信息。

查看源代码:http://appliedcodelog.blogspot.in/2015/08/login-by-google-account-integration-for.html

【讨论】:

  • 嗨,Suchi,前两天我正在尝试使用您的代码在 Xamarin Android 中进行 Google Plus 登录。但我失败了。我看过你的文章,Xamarin Form讨论并尝试了每一件事,但仍然面临问题。请帮忙。
  • 在第 3 步中:当我尝试使用访问令牌访问用户信息时,会出现 403 错误作为响应。像这样的 JSON:“code”:403,“message”:“已超过未经身份验证使用的每日限制。继续使用需要注册。”
  • 我也尝试过创建新的客户端 ID,但仍然显示相同的错误
  • 确保访问令牌没有过期。
  • 今天累了就显示:code": 401, "message": "Invalid Credentials"
猜你喜欢
  • 1970-01-01
  • 2018-03-08
  • 2016-11-09
  • 2017-03-11
  • 2018-10-19
  • 1970-01-01
  • 2019-05-22
  • 2019-08-15
  • 2012-04-23
相关资源
最近更新 更多