我在Google Cloud Endpoints Android应用中首次尝试在调试模式下使用身份验证时遇到问题.我设置了这样的凭据:
credential = GoogleAccountCredential.usingAudience(this,
"server:client_id:long-string-i-got-from-api-console");
credential.setSelectedAccountName(accountName);
Run Code Online (Sandbox Code Playgroud)
然后尝试像这样使用它:
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 ...
Run Code Online (Sandbox Code Playgroud)
但尝试失败,我在logCat中收到这些消息:
03-06 23:33:20.418:W/System.err(11861):引起: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)