Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google endpoint method keeps returning "name must not be empty" exception

The endpoint method looks like this:

@Api(
    name = "gameape",
    version = "v1",
    description = "Game App API",
    audiences = { "mynumber.apps.googleusercontent.com" },
    clientIds = { "mynumber.apps.googleusercontent.com", Constant.API_EXPLORER_CLIENT_ID },
    defaultVersion = AnnotationBoolean.TRUE)
public class GameApp {

    private final AccountDao accountDao = new AccountDaoImpl();

    @ApiMethod(name = "LoginUser", path = "LoginUser", httpMethod = HttpMethod.POST)
    public void LoginUser(LoginData request) {
        long phone = request.getPhone();
        String deviceId = request.getDeviceId();
        String gcmToken = request.getGcmToken();
        Account acc = new Account(phone, deviceId, gcmToken);
        accountDao.put(acc);
        ApiHelper.sendGCM(phone, "welcome to my game app");
    }
}

The snippet from android looks like this:

@Override
protected Boolean doInBackground(Void... params) {
    LoginData request = new LoginData();
    request.setUsername(username);
    request.setPassword(password);

   try {
     RegisterUser reg = service.registerUser(request);
     reg.execute();
     return true;
   } catch (Exception e) {
     Log.e(LoginActivity.class.getName(),
        "Exception received from server at "
         + service.getRootUrl(), e);
   }
   return false;
}

Calling reg.execute() keeps throwing the exception:

java.lang.IllegalArgumentException: the name must not be empty: null

From the server console, it does not even look like the server is being hit. Even when I try running the server in debug mode, my breakpoint (first line inside method) is not reached.

EDIT: adding stack trace:

04-03 13:38:42.688: I/com.me.gameapp.LoginActivity$UserLoginTask(11255): Enter doInBackground
04-03 13:38:42.786: E/com.me.gameapp.LoginActivity(11255): Exception received from server at https://1.myapp.appspot.com/_ah/api/
04-03 13:38:42.786: E/com.me.gameapp.LoginActivity(11255): java.lang.IllegalArgumentException: the name must not be empty: null
04-03 13:38:42.786: E/com.me.gameapp.LoginActivity(11255):  at android.os.Parcel.readException(Parcel.java:1251)
04-03 13:38:42.786: E/com.me.gameapp.LoginActivity(11255):  at android.os.Parcel.readException(Parcel.java:1235)
04-03 13:38:42.786: E/com.me.gameapp.LoginActivity(11255):  at com.google.android.gms.internal.x$a$a.a(Unknown Source)
04-03 13:38:42.786: E/com.me.gameapp.LoginActivity(11255):  at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
04-03 13:38:42.786: E/com.me.gameapp.LoginActivity(11255):  at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
04-03 13:38:42.786: E/com.me.gameapp.LoginActivity(11255):  at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.getToken(GoogleAccountCredential.java:192)
04-03 13:38:42.786: E/com.me.gameapp.LoginActivity(11255):  at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential$RequestHandler.intercept(GoogleAccountCredential.java:217)
04-03 13:38:42.786: E/com.me.gameapp.LoginActivity(11255):  at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:836)
04-03 13:38:42.786: E/com.me.gameapp.LoginActivity(11255):  at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:412)
04-03 13:38:42.786: E/com.me.gameapp.LoginActivity(11255):  at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:345)
04-03 13:38:42.786: E/com.me.gameapp.LoginActivity(11255):  at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:463)
04-03 13:38:42.786: E/com.me.gameapp.LoginActivity(11255):  at com.me.gameapp.LoginActivity$UserLoginTask.doInBackground(LoginActivity.java:262)
04-03 13:38:42.786: E/com.me.gameapp.LoginActivity(11255):  at com.me.gameapp.LoginActivity$UserLoginTask.doInBackground(LoginActivity.java:1)
04-03 13:38:42.786: E/com.me.gameapp.LoginActivity(11255):  at android.os.AsyncTask$2.call(AsyncTask.java:185)
04-03 13:38:42.786: E/com.me.gameapp.LoginActivity(11255):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
04-03 13:38:42.786: E/com.me.gameapp.LoginActivity(11255):  at java.util.concurrent.FutureTask.run(FutureTask.java:137)
04-03 13:38:42.786: E/com.me.gameapp.LoginActivity(11255):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
04-03 13:38:42.786: E/com.me.gameapp.LoginActivity(11255):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
04-03 13:38:42.786: E/com.me.gameapp.LoginActivity(11255):  at java.lang.Thread.run(Thread.java:1096)
04-03 13:38:42.786: I/com.me.gameapp.LoginActivity$UserLoginTask(11255): Leave doInBackground with false

In the line Exception received from server at https://1.myapp.appspot.com/_ah/api/, I am running everything on localhost. Maybe https://1.myapp.appspot.com/_ah/api/ is wrong. My code is very close to the template, though, so I am not sure that's a change I committed.

like image 663
learner Avatar asked Apr 03 '13 20:04

learner


4 Answers

Here the name being referred is the selected account name, not the application name.

Also on android 6.0 you need to get the Contacts permission before you invoke google endpoints. Otherwise even if you set the account name using

credential.setSelectedAccountName(accountName);

You will still get the exception mentioned above.

like image 147
Vikas Avatar answered Nov 15 '22 08:11

Vikas


Had a similar error message when testing this out for myself, what solved it for me was using

credential.setSelectedAccountName("[email protected]");

before running

SomeAbstractGoogleJsonClient.Builder builder = new SomeAbstractGoogleJsonClient.Builder(
AndroidHttp.newCompatibleTransport(), new GsonFactory(), credential);

assuming similar code is somewhere in your app. As you have only posted the snippet from your caller thread it's kinda hard to tell.

like image 34
user2072160 Avatar answered Nov 15 '22 09:11

user2072160


My solution was to use

credential.setSelectedAccount(new Account(settings.getString(Constants.PREF_ACCOUNT_NAME, null), "com.example.myapplication"));

So I used setSelectedAccount instead of setSelectedAccountName

like image 39
marcolav Avatar answered Nov 15 '22 08:11

marcolav


Setting accountname did not work for me , i had to set selectedaccount as marco said . To simplify his answer

   credential = GoogleAccountCredential.usingOAuth2(context, scopes);
    credential.setSelectedAccount(new Account("[email protected]", "com.your.pakagename"));
like image 21
Manohar Avatar answered Nov 15 '22 08:11

Manohar