gpt4 book ai didi

android - 谷歌验证异常 : Unknown when authenticating with Cloud Endpoints

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:21:44 25 4
gpt4 key购买 nike

我正在尝试向我的 Cloud Endpoints 添加身份验证,但无法正常工作。我使用这个博客作为指南:http://devthots.blogspot.nl/2012/07/building-awesome-android-apps-with.html

我有什么:

在 AppEngine 项目中:

@Api(name = "noteendpoint", clientIds = { "123456789012-abcdefghijklmnopqrstuvwxyz012345.apps.googleusercontent.com" }, audiences = { "my_project_id.appspot.com" }, namespace = @ApiNamespace(ownerDomain = "example.com", ownerName = "example.com", packagePath = "myapp"))
public class NoteEndpoint {
// Rest of class, added parameter User to all methods.
}

在我的 Android 应用项目中:

Note note = new Note();     
note.setDescription("Description!");

GoogleAccountCredential credential =
GoogleAccountCredential.usingAudience(MainActivity.this, "my_project_id.appspot.com");
credential.setSelectedAccountName(ACCOUNT_NAME);

note.setEmailAddress(credential.getSelectedAccountName());

Builder endpointBuilder = new Noteendpoint.Builder(
AndroidHttp.newCompatibleTransport(),
new JacksonFactory(), credential);

Noteendpoint endpoint = CloudEndpointUtils.updateBuilder(endpointBuilder).build();
Note result = endpoint.insertNote(note).execute(); // Exception thrown

当我运行它时,抛出一个 GoogleAuthException: Unknown:

07-08 14:16:45.677: E/AndroidRuntime(27381): Caused by: com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAuthIOException
07-08 14:16:45.677: E/AndroidRuntime(27381): at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential$RequestHandler.intercept(GoogleAccountCredential.java:308)
07-08 14:16:45.677: E/AndroidRuntime(27381): at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:854)
07-08 14:16:45.677: E/AndroidRuntime(27381): at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:410)
07-08 14:16:45.677: E/AndroidRuntime(27381): at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:343)
07-08 14:16:45.677: E/AndroidRuntime(27381): at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460)
07-08 14:16:45.677: E/AndroidRuntime(27381): at com.example.test.ui.MainActivity$1.doInBackground(MainActivity.java:131)
07-08 14:16:45.677: E/AndroidRuntime(27381): ... 7 more
07-08 14:16:45.677: E/AndroidRuntime(27381): Caused by: com.google.android.gms.auth.GoogleAuthException: Unknown
07-08 14:16:45.677: E/AndroidRuntime(27381): at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
07-08 14:16:45.677: E/AndroidRuntime(27381): at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
07-08 14:16:45.677: E/AndroidRuntime(27381): at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.getToken(GoogleAccountCredential.java:277)
07-08 14:16:45.677: E/AndroidRuntime(27381): at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential$RequestHandler.intercept(GoogleAccountCredential.java:301)

我该如何解决这个问题?

用于 NoteEndpoint 类的 clientId 是从“已安装应用程序的客户端 ID”复制而来的,带有我的调试 key sha1。

使用 GoogleAccountCredential.usingAudience(MainActivity.this, "server:client_id:my_project_id.appspot.com");(因此带有 server:client_id: 前缀)不会帮助。

最佳答案

生成 Android 客户端 ID 时要小心。输入包名时,使用写在app/build.gradle中的应用ID。它可能与您的源类的包不同。

解释:

在项目创建时,您输入的包名称被 Android 用作应用程序 ID,并用于为您的源类生成包。在项目开发过程中,您可能会更改源类的包名。但要小心,Android Studio 不会自动更改您的应用程序 ID!

关于android - 谷歌验证异常 : Unknown when authenticating with Cloud Endpoints,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17526658/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com