gpt4 book ai didi

android - Google端点方法不断返回 "name must not be empty"异常

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:22:22 25 4
gpt4 key购买 nike

端点方法如下所示:

@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 的代码 fragment 如下所示:

@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

从服务器控制台看,它甚至看起来都不像服务器被攻击了。即使我尝试在 Debug模式下运行服务器,我的断点(方法内的第一行)也没有到达。

编辑:添加堆栈跟踪:

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

Exception received from server at https://1.myapp.appspot.com/_ah/api/ 行中,我在本地主机上运行所有内容。也许 https://1.myapp.appspot.com/_ah/api/ 是错误的。不过,我的代码与模板非常接近,所以我不确定这是不是我提交的更改。

最佳答案

此处引用的名称是选定的帐户名称,而不是应用程序名称。

同样在 android 6.0 上,您需要在调用 google 端点之前获得联系人权限。否则即使您使用

设置帐户名
credential.setSelectedAccountName(accountName);

你仍然会得到上面提到的异常。

关于android - Google端点方法不断返回 "name must not be empty"异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15797228/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com