android - Android 应用程序中的云端点身份验证失败

标签 android google-cloud-endpoints

我第一次尝试在 Google Cloud Endpoints Android 应用程序的 Debug模式下使用身份验证时遇到了问题。我这样设置凭据:

credential = GoogleAccountCredential.usingAudience(this,
           "server:client_id:long-string-i-got-from-api-console");
credential.setSelectedAccountName(accountName);

然后尝试像这样使用它:

final String LOCAL_APP_ENGINE_SERVER_URL = "http://xxx.xxx.x.xxx:8888"; 
Testdbendpoint.Builder endpointBuilder = new Testdbendpoint.Builder(
            AndroidHttp.newCompatibleTransport(),
            new GsonFactory(),
            credential);
endpointBuilder.setRootUrl(LOCAL_APP_ENGINE_SERVER_URL + "/_ah/api/");
Testdbendpoint endpoint = endpointBuilder.build();
try {
    TestDB testDB = new TestDB().setId(10101L);                      
    TestDB result = endpoint.insertTestDB(testDB).execute();  //-- fails here!!!!
} catch ...

但尝试失败,我在 logCat 中收到这些消息:

03-06 23:33:20.418: W/System.err(11861): Caused by: com.google.android.gms.auth.GoogleAuthException: Unknown 03-06 23:33:20.418: W/System.err(11861): at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source) 03-06 23:33:20.423: W/System.err(11861): at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source) 03-06 23:33:20.428: W/System.err(11861): at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.getToken(GoogleAccountCredential.java:192)

最佳答案

也许您的 Android 客户端 ID 的证书指纹 (SHA1) 有误?仅当您手动签署 .apk 时,使用生产 key 指纹的身份验证才有效。

在您的 API Console 中使用您的 debug.keystore 指纹为已安装的应用程序 (Android) 注册一个客户端 ID。 .要获取指纹使用:

C:\>keytool -list -alias androiddebugkey -keystore C:\.android\debug.keystore -storepass android -keypass android

您还需要一个 Web-Client-Id 并在您的 Android 应用程序中将其设置为 Audience:

credential = GoogleAccountCredential.usingAudience(this,"server:client_id:" + WEB_CLIENT_ID);

AppEngine 端点配置应如下所示:

@Api(
    name = "testEndpoint",
    version = "v1",
    clientIds = {ClientIds.WEB_ID, ClientIds.ANDROID_PRODUCTION_ID, ClientIds.ANDROID_DEBUG_ID},
    audiences = {ClientIds.WEB_ID}

)

关于android - Android 应用程序中的云端点身份验证失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15263228/

相关文章:

java - 当我未登录时,Google 的 API 资源管理器不适用于我的 Google 部署

android - 如何在 Android 中为硬件按钮设置事件处理程序?

android - Twitter REST API v1即将停止运行

android - 无法为 com.google.cloud.tools.gradle.appengine.core.AppEngineExtension 类型的对象设置未知属性 'httpAddress'

google-app-engine - 测试、问题跟踪、持续集成——为 GAE 和 Android 应用程序推荐的标准工具

python - 导入错误 : No module named endpoints_proto_datastore. ndb

android - Android 内存指南中的 "Avoid dependency injection frameworks"是否也适用于 Dagger?

android - 如何给抽屉导航的菜单项上色?

java - 使用 FusedLocationApi 启用/禁用监听器?

java - 将 Android 应用程序连接到 Google Cloud Endpoints : could not find class 时出错