我在Google Cloud Endpoints的Android应用程序中第一次尝试使用调试模式进行身份验证,但遇到了问题。我是这样设置凭据的:
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中得到这些消息:
此处尝试获取令牌失败并在logCat中出现了上述错误消息。03-06 23:33:20.418: W/System.err(11861): Caused by: com.google.android.gms.auth.GoogleAuthException: 未知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)