android – Google端点方法不断返回“name must not empty”异常

前端之家收集整理的这篇文章主要介绍了android – Google端点方法不断返回“name must not empty”异常前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
端点方法如下所示:
@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");
    }
}

android的片段如下所示:

@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;
}

调用reg.execute()不断抛出异常:

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

从服务器控制台,它甚至看起来不像服务器被击中.即使我尝试在调试模式下运行服务器,也未达到我的断点(方法内的第一行).

编辑:添加堆栈跟踪:

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

在服务器https://1.myapp.appspot.com/_ah/api/收到的Exception行中,我正在运行localhost上的所有内容.也许https://1.myapp.appspot.com/_ah/api/错了.我的代码非常接近模板,所以我不确定这是我提交的更改.

解决方法

这里引用的名称是选定的帐户名称,而不是应用程序名称.

同样在Android 6.0上,您需要在调用Google端点之前获取“联系”权限.否则即使您使用设置帐户名称

credential.setSelectedAccountName(accountName);

你仍然会得到上面提到的例外.

猜你在找的Android相关文章