1

I can't understand why my endpoint works perfectly fine in Google APIs Explorer and not on Android.

https://developers.google.com/apis-explorer/?base=https://prncts.appspot.com/_ah/api#p/pronocities/v1.0.1/pronocities.content.get?id=aghzfnBybmN0c3IJCxIBZBj5zAMM&_h=1&

In fact it almost works as I can see that the call is made to my GAE endpoint server side and that the user perfectly authentified via OAuth.

There seems to be something wrong in the way the data is sent back to the phone.

Here are the logs I get on the phone :

07-28 15:12:53.305: W/System.err(3034): com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
07-28 15:12:53.305: W/System.err(3034): {
07-28 15:12:53.305: W/System.err(3034):   "code": 400,
07-28 15:12:53.305: W/System.err(3034):   "errors": [
07-28 15:12:53.305: W/System.err(3034):     {
07-28 15:12:53.305: W/System.err(3034):       "domain": "global",
07-28 15:12:53.305: W/System.err(3034):       "message": "java.lang.IllegalArgumentException: name cannot be null or empty",
07-28 15:12:53.305: W/System.err(3034):       "reason": "badRequest"
07-28 15:12:53.305: W/System.err(3034):     }
07-28 15:12:53.305: W/System.err(3034):   ],
07-28 15:12:53.305: W/System.err(3034):   "message": "java.lang.IllegalArgumentException: name cannot be null or empty"
07-28 15:12:53.305: W/System.err(3034): }
07-28 15:12:53.305: W/System.err(3034):     at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:111)

The object sent back is a really simple POJO as you can see in Google APIs Explorer.

EDIT1:

Android side code mostly taken from the TicTacToe example :

settings = getSharedPreferences("PronoCities", 0);
credential = GoogleAccountCredential.usingAudience(
        this, "server:client_id:<myid>.apps.googleusercontent.com");
setAccountName(settings.getString(PREF_ACCOUNT_NAME, null));

Pronocities.Builder builder = new Pronocities.Builder(
        AndroidHttp.newCompatibleTransport(), new GsonFactory(), credential);
service = builder.build();

Any help will be greatly appreciated.

François

Using google-api-client-1.15.0-rc librairies and running on a Samsung Galaxy S3 / Android 4.1.2.

mably
  • 166
  • 2
  • 7
  • If you are using OAuth, have you properly included both a WEB and ANDROID client id? Please share your Android side credentials code (less your actual ids). – jdub Jul 29 '13 at 18:59
  • Yep, I can see that the request arrives server side with the right user being correctly authenticated. But for an unknown reason, GAE sends back a 400 bad request response. Everything works fine with APIs Explorer. And the endpoint is supposed to work even if User parameter is null. – mably Jul 29 '13 at 19:18

1 Answers1

2

It seems likely that the error is originating from Datastore, not Endpoints. Please double check that the URLs in both the Explorer and Android requests are identical, and also check any Datastore operations you're making in your test case. In particular, check to make sure if you create Datastore Key objects that they have names.

saiyr
  • 2,575
  • 1
  • 11
  • 13
  • 1
    You're totally right. In fact I am using the getUserId method on the User object to retrieve the user entity from datastore. Le user ID is properly populated when using Google APIs explorer but is empty when using Android. It's related to this : [link](http://stackoverflow.com/questions/16661109/google-endpoints-api-chrome-extension-returns-none-for-endpoints-get-current-u/16661765#16661765). Thanx for again for your help. Still have to find a solution for this though. – mably Jul 30 '13 at 10:17