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}
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With