云端点认证失败的Andr​​oid应用程序云端、应用程序、Andr、oid

2023-09-07 11:20:09 作者:还念当初。

我有我使用了谷歌云端点Android应用程序在调试模式下认证的第一次尝试的麻烦。我设置了这样的凭据:

 凭证= GoogleAccountCredential.usingAudience(这一点,
           服务器:CLIENT_ID:长串-I-了 - 从-API控制台);
credential.setSelectedAccountName(帐户名);
 

然后尝试使用这样的:

 最后弦乐LOCAL_APP_ENGINE_SERVER_URL =htt​​p://xxx.xxx.x.xxx:8888;
Testdbendpoint.Builder endpointBuilder =新Testdbendpoint.Builder(
            AndroidHttp.newCompatibleTransport(),
            新GsonFactory(),
            凭据);
endpointBuilder.setRootUrl(LOCAL_APP_ENGINE_SERVER_URL +/ _ah / API /);
Testdbendpoint端点= endpointBuilder.build();
尝试 {
    TestDB的TESTDB =新TestDB的()SETID(10101L)。
    TestDB的结果= endpoint.insertTestDB(TESTDB).execute(); //  - 失败这里!!!!
} 抓住 ...
 

但尝试失败,我得到这些消息的logcat:

  

03-06 23:33:20.418:W / System.err的(11861):产生的原因:   com.google.android.gms.auth.GoogleAuthException:未知03-06   23:33:20.418:W / System.err的(11861):在   com.google.android.gms.auth.GoogleAuthUtil.getToken(来源不明)   03-06 23:33:20.423:W / System.err的(11861):在   com.google.android.gms.auth.GoogleAuthUtil.getToken(来源不明)   03-06 23:33:20.428:W / System.err的(11861):在   com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.getToken(GoogleAccountCredential.java:192)

解决方案

也许你有错误的证书指纹(SHA1)为你的Andr​​oid客户端ID?随着生产的关键指纹认证只有当你手动签署.apk文件。

注册一个客户端ID已安装的应用程序(安卓)与你的debug.keystore指纹在 API控制台。要获取指纹的使用:

  C:\>的keytool -list -alias androiddebugkey -keystore C:\机器人\ debug.keystore -storepass安卓-keypass机器人
 

此外,您需要一个网络客户端ID并将其设置为读者在你的Andr​​oid应用程序:

 凭证= GoogleAccountCredential.usingAudience(这一点,服务器:CLIENT_ID:+ WEB_CLIENT_ID);
 

AppEngine上端点配置应该是这样的:

  @Api(
    NAME =testEndpoint
    版本=V1,
    的ClientID = {ClientIds.WEB_ID,ClientIds.ANDROID_PRODUCTION_ID,ClientIds.ANDROID_DEBUG_ID},
    观众= {ClientIds.WEB_ID}
 

I'm having trouble with my first attempt to use authentication in debug mode in a Google Cloud Endpoints android app. I set up credentials like this:

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

then try to use it like this:

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 ...

But the try fails and I get these messages in 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)

解决方案

Maybe you have the wrong Certificate fingerprint (SHA1) for your Android Client-Id? The authentication with the fingerprint of your production key works only if you sign the .apk manually.

Register a Client-Id for an Installed Application (Android) with your debug.keystore fingerprint in your API Console. To get the fingerprint use:

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

Also you need a Web-Client-Id and set it as Audience in your Android application:

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

AppEngine Endpoint configuration should look like this:

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

)