简体   繁体   English

Google Api和android Oauth INVALID_AUDIENCE错误

[英]Google Api and android Oauth INVALID_AUDIENCE error

I am getting a GoogleAuthException: Unknown error , while doing a GoogleAuthUtil.getToken . 我得到一个GoogleAuthException: Unknown error ,同时做一个GoogleAuthUtil.getToken

Just before the exception I see 就在我看到的例外之前

GLSUser: GLS error: INVALID_AUDIENCE <email> audience:server:client_id:xxx.apps.googleusercontent.com

I have set the SHA1 from my release key , the package name, to the google api project. 我已将SHA1从我的发布密钥(包名称)设置为google api项目。 (Which by the way is being used successfully for GCM. ) (顺便说一句,这是成功用于GCM的。)

Looks like that should work; 看起来应该有用; here's the scope-init code from my app which does work. 这是我的应用程序中的scope-in​​it代码,它可以正常工作。

private static final String SCOPE = "audience:server:client_id:" + SERVER_CLIENT_ID;

So it smells to me like there's a problem with the client id. 因此,我觉得客户端ID存在问题。 Remember that 记住这一点

  1. You have to have a project with two client ids 您必须有一个包含两个客户端ID的项目
  2. One is the one for your android app, with the SHA & package & so on 一个是你的Android应用程序,包括SHA和包等
  3. The other is for the server side that you're going to send the token off to 另一个是服务器端,您将要发送令牌

It's the client ID from #3 that goes after ...:client_id: 它是#3之后的客户端ID ...:client_id:

In the interest of documenting my issue, 为了记录我的问题,

I had the same INVALID_AUDIENCE error come back from a Google sign-in through an AWS Mobile Hub generated sample app. 我通过AWS Mobile Hub生成的示例应用从Google登录中获得了相同的INVALID_AUDIENCE错误。 A few things to check, 要检查的一些事情,

Like Tim Bray notes aboves, make your client id a valid web client id (not Android). 就像Tim Bray注意到的那样,让你的客户端ID成为有效的Web客户端ID(不是Android)。 But also have an android client id that has both the proper SHA-1 Fingerprint (found in debug.keystore which Android Studio uses to sign debug builds when you click Run) and package name. 但是也有一个android客户端ID,它具有正确的SHA-1指纹(在debug.keystore中找到,Android Studio用来在单击Run时签署调试版本)和包名称。

NOTE: The package name listed in the AndroidManifest.xml is not always the actual package name. 注意:AndroidManifest.xml中列出的软件包名称并不总是实际的软件包名称。 To find the definitive package name, go to the build.gradle file and see the applicationId field. 要查找确定的包名称,请转到build.gradle文件并查看applicationId字段。 Be sure to input the right package name in the Developers Console when you configure the Android Client Id. 配置Android客户端ID时,请务必在Developers Console中输入正确的软件包名称。

Happened to one on my team although it worked ok on my device. 虽然它在我的设备上工作正常,却发生在我的团队中。 It turned out to be because of a different debug.keystore on our eclipse installations. 原来是因为我们的eclipse安装中有一个不同的debug.keystore

To solve it we've copied the company's debug.keystore file to ~/.android/ (this is the dir on a mac, it's different on linux and windows) 为了解决这个问题,我们将公司的debug.keystore文件复制到了~/.android/ (这是mac上的dir,在linux和windows上是不同的)

Solve this by deleting your debug.keystore found in your .android folder, then run the new project again to generate a new debug.keystore file. 通过删除.android文件夹中找到的debug.keystore来解决此问题,然后再次运行新项目以生成新的debug.keystore文件。 Then finally generate a new SHA-1 signing-certificate for Google API. 然后,最终为Google API生成新的SHA-1签名证书。

Also you have to set up oAuth authorization screen in your Google API Console. 您还必须在Google API控制台中设置oAuth授权屏幕。

That was why I got this error 这就是我收到这个错误的原因

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google OAuth 2.0 API出现INVALID_AUDIENCE错误 - INVALID_AUDIENCE error with Google OAuth 2.0 API GLS错误:Google云端点中的INVALID_AUDIENCE - GLS error: INVALID_AUDIENCE in google cloud endpoints Android Auth错误:“ GetToken失败,状态码:INVALID_AUDIENCE” - Android Auth Error: “GetToken failed with status code: INVALID_AUDIENCE” 为什么使用Google端点会收到INVALID_AUDIENCE? - Why do I get INVALID_AUDIENCE using Google Endpoints? 获取&#39;E / TokenRequestor:您有与OAuth2相关的错误配置。 详细错误:INVALID_AUDIENCE&#39;即使在提供准确的客户ID之后也是如此 - Getting 'E/TokenRequestor: You have wrong OAuth2 related configurations. Detailed error: INVALID_AUDIENCE' even after providing accurate client IDs android:谷歌APi OAuth 2.0-错误400获取用户信息 - android: google APi OAuth 2.0 - error 400 getting user info 我的Android客户端中的Google Cloud Endpoint身份验证:不允许受众,并且Oauth框架用户与oauth令牌用户不匹配 - Google Cloud Endpoint Authentication from my Android Client: Audience not Allowed and Oauth framework user didn't match oauth token user Android:Google Data API-401令牌无效错误 - Android: Google Data API - 401 Token Invalid Error 从 Android 获取 Google oauth 授权令牌 - 返回无效范围/未知错误 - getting Google oauth authorization token from Android- return with invalid_scope/ Unknown error Uber API Android oAuth-浏览器登录屏幕无效的URL - Uber API Android oAuth - Browser Login Screen Invalid URL
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM