新发布的“使用Google Play服务进行身份验证”,通过GoogleAuthUtil.getToken获取令牌的问题

2024-04-07

Update:

刚才我使用我也用于 Google App Engine 的 Google 帐户注册了 Google API,现在错误已更改为com.google.android.gms.auth.GoogleAuthException: Unknown


谷歌刚刚发布了一种新方法通过 Google 帐户注册自己的应用 https://developers.google.com/android/google-play-services/authentication并在他们的文章中给出了一些解释blogpost http://android-developers.blogspot.com.au/2012/09/google-play-services-and-oauth-identity.html, too.

我正在编写一个 Android 应用程序,您必须注册才能创建用户帐户,并且我正在使用 Google App Engine 作为后端。通过播放服务,我希望获得与 Android 设备关联的用户电子邮件和令牌。我已经可以收到电子邮件,但是,获取令牌只会引发错误,并且由于文档非常稀疏,我不知道如何解决这些问题。这就是我收到电子邮件的方式:

private String[] getAccountNames() {
    mAccountManager = AccountManager.get(this);
    Account[] accounts = mAccountManager.getAccountsByType(GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE);
    names = new String[accounts.length];
    for (int i = 0; i < names.length; i++) {
        names[i] = accounts[i].name;
    }

    return names;
}

然而,当我打电话时token = GoogleAuthUtil.getToken(context, email, "scope",它给了我这些错误:GooglePlayServices not available due to error 1 and com.google.android.gms.auth.GooglePlayServicesAvailabilityException: GooglePlayServicesNotAvailable.

现在我的问题是,我是否必须设置任何权限或包含任何库来解决这个问题?范围参数是什么?他们的博客文章中给出了如何获取令牌以及为范围添加什么内容的示例,以将范围变量设置为"https://www.googleapis.com/auth/userinfo.profile"但不幸的是我仍然遇到同样的错误。

我还为 Google API 控制台注册了我的应用程序并启用了 G+ API,我还需要在那里配置其他内容吗?


我在使用 Google Drive 的 Google 客户端库时遇到了同样的问题。 解决方案非常简单。只需将“oauth2:”添加到您的scopeUrl 中即可。

Wrong:

GoogleAuthUtil.getToken(this, account.name, DriveScopes.DRIVE);

Right:

GoogleAuthUtil.getToken(this, account.name, "oauth2:" + DriveScopes.DRIVE);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

新发布的“使用Google Play服务进行身份验证”,通过GoogleAuthUtil.getToken获取令牌的问题 的相关文章

随机推荐