GLS Error: INVALID_AUDIENCE at Google Endpoints

I am trying to get google endpoints to work. I created an endpoint service and was able to verify that it works fine using the Google API. Then I generated the android client and tried to call the endpoint service. I see this error in the log,

04-05 08:48:20.547: I/GLSUser(13505): GLS error: INVALID_AUDIENCE myemail@gmail.com audience:server:client_id:334082396285-hfn3t2g5pg0gv8fshf22kaadq9fs23e2.apps.googleusercontent.com

Here is my java code for Android to create the credentials that I used to access my service,

AUDIENCE = "server:client_id:334082396285-hfn3t2g5pg0gv8fshf22kaadq9fs23e2.apps.googleusercontent.com";
credential = GoogleAccountCredential.usingAudience(this, AUDIENCE);
            setAccountName(settings.getString(PREF_ACCOUNT_NAME, null));

There seems to be some mismatch in client_id. Here is what I did

1) Created 2 client_ids in the Google API console in one API project, a) WEB_CLIENT_ID = I created client_id for web applications with URI Redirect = No and JavaScript source code = No. b) ANDROID_CLIENT_ID = Created a client_id for an Android application with the package name and certificate fingerprint sha1.

2) Then they were used in my endpoint service in python,

@endpoints.api(name='devices',
               version='v1',
               description='Service to register devices',
               allowed_client_ids=[ANDROID_CLIENT_ID,WEB_CLIENT_ID,endpoints.API_EXPLORER_CLIENT_ID],
               audiences = [WEB_CLIENT_ID])

Full magazine

04-05 08:48:20.397: D/overlay(159): Set pipe=RGB1 dpy=0; Set pipe=VG0 dpy=0; 
04-05 08:48:20.547: W/GLSUser(13505): Status from wire: INVALID_AUDIENCE status: null
04-05 08:48:20.547: W/GLSUser(13505): Status from wire: INVALID_AUDIENCE status: null
04-05 08:48:20.547: I/GLSUser(13505): GLS error: INVALID_AUDIENCE myemail@gmail.com audience:server:client_id:334082396285-hfn3t2g5pg0gv8fshf22kaadq9fs23e2.apps.googleusercontent.com
04-05 08:48:20.547: W/GLSUser(13505): Status from wire: Unknown status: UNKNOWN
04-05 08:48:20.547: W/System.err(31908): com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAuthIOException
04-05 08:48:20.547: W/System.err(31908):    at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential$RequestHandler.intercept(GoogleAccountCredential.java:224)
04-05 08:48:20.547: W/System.err(31908):    at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:836)
04-05 08:48:20.547: W/System.err(31908):    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:412)
04-05 08:48:20.557: W/System.err(31908):    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:345)
04-05 08:48:20.557: W/System.err(31908):    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:463)
04-05 08:48:20.557: W/System.err(31908):    at com.package.appname.SetupActivity$SendResultToServerTask.doInBackground(SetupActivity.java:174)
04-05 08:48:20.557: W/System.err(31908):    at com.package.appname.SetupActivity$SendResultToServerTask.doInBackground(SetupActivity.java:1)
04-05 08:48:20.557: W/System.err(31908):    at android.os.AsyncTask$2.call(AsyncTask.java:287)
04-05 08:48:20.557: W/System.err(31908):    at java.util.concurrent.FutureTask.run(FutureTask.java:234)
04-05 08:48:20.557: W/System.err(31908):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
04-05 08:48:20.557: W/System.err(31908):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
04-05 08:48:20.557: W/System.err(31908):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
04-05 08:48:20.557: W/System.err(31908):    at java.lang.Thread.run(Thread.java:856)
04-05 08:48:20.557: W/System.err(31908): Caused by: com.google.android.gms.auth.GoogleAuthException: Unknown
04-05 08:48:20.557: W/System.err(31908):    at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
04-05 08:48:20.557: W/System.err(31908):    at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)

Already seen similar topics, and they did not help, Google Api error and android Oauth INVALID_AUDIENCE

+5
source share
5 answers
+4

, google api.

API [API auth] β†’ [ ]

+6

, ANDROID_CLIENT_ID, @Api # clientIds, Android, Android-.

Eg

@Api(
    name = "yourFirstService",
    version = "v1",
    namespace = @ApiNamespace(ownerDomain = "myorg.org", ownerName = "My Org", packagePath = "firstservice" ),
    scopes = {Constant.API_EMAIL_SCOPE},
    clientIds = {Constants.ANDROID_CLIENT_ID, Constant.API_EXPLORER_CLIENT_ID},
    audiences = {Constants.ANDROID_AUDIENCE}
)
public class YourFirstAPI { 
  ...
}

clientId. ANDROID_CLIENT_ID

  • clientId Cloud Console->APIS & Auth->Credentials->Client ID for Android.
  • , Android, .
+3

, . Android Studio . , , , INVALID_AUDIENCE. , , debug.keystore . Windows % USERPROFILE%.android. , debug.keystore Android Studio . debug.keystore (365 , ), . , debug.keystore . debug.keystore Android Studio . keytool, SHA1. http://console.developers.google.com to create a new customer ID using a fingerprint.

+2
source

One thing happened on my team, although everything worked fine on my device. This turned out to be due to another debug.keystoreon our eclipse installations.

To solve the problem, we copied the debug.keystorecompany file ~/.android/ (this is a directory on mac, it differs from linux and windows)

+2
source

All Articles