更新:
刚才我使用我用于Google App Engine的Google帐户注册了Google API,现在错误已更改为 com.google.android.gms.auth.GoogleAuthException: Unknown
谷歌刚刚发布了一种通过谷歌账户注册一个应用程序的新方法,并在他们的博客帖子中给出了一些解释.
我正在编写一个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;
}
Run Code Online (Sandbox Code Playgroud)
但是,当我打电话时token = GoogleAuthUtil.getToken(context, email,
"scope",它给了我这些错误:
GooglePlayServices not available due to error 1和com.google.android.gms.auth.GooglePlayServicesAvailabilityException: GooglePlayServicesNotAvailable.
现在我的问题是,我是否必须设置任何权限或包含任何库来解决这个问题?什么是范围参数?在他们的博客文章中给出了如何获取令牌以及放入范围的内容的示例,以将范围变量设置为"https://www.googleapis.com/auth/userinfo.profile"但不幸的是我仍然得到相同的错误.
我还为Google API控制台注册了我的应用并启用了G + API,我是否还必须配置其他内容?
Bas*_*der 20
我使用谷歌驱动器的谷歌客户端库存在同样的问题.解决方案非常简单.只需在您的scopeUrl中添加"oauth2:".
错误:
GoogleAuthUtil.getToken(this, account.name, DriveScopes.DRIVE);
Run Code Online (Sandbox Code Playgroud)
对:
GoogleAuthUtil.getToken(this, account.name, "oauth2:" + DriveScopes.DRIVE);
Run Code Online (Sandbox Code Playgroud)
您只能获取支持 OAuth2 的 Google 服务的令牌。如果您正在编写自己的 Web 服务,则应该使用其本机身份验证机制(用户名和密码?)对其进行身份验证。“范围”显然是无效范围,但您似乎没有安装 Google Play 服务,这就是错误的原因。您可以从 Play 商店安装它,但它实际上并不适合您,因为您没有使用 Google 服务。
| 归档时间: |
|
| 查看次数: |
8936 次 |
| 最近记录: |