向 Cloud Endpoint 添加参数导致 404 GoogleJsonResponseException
Adding parameters to Cloud Endpoint causes 404 GoogleJsonResponseException
我在完成示例 GCM 消息传递 (https://github.com/GoogleCloudPlatform/gradle-appengine-templates/tree/master/GcmEndpoints)
时遇到问题
一切正常,直到我想向 RegistrationEndpoint
class 中的 registerDevice
方法添加额外的参数。我确定我之前添加了 @Named
。
更改前如下所示:
@ApiMethod(name = "register")
public void registerDevice(@Named("regId") String regId) {
if (findRecord(regId) != null) {
log.info("Device " + regId + " already registered, skipping register");
return;
}
RegistrationRecord record = new RegistrationRecord();
record.setRegId(regId);
//record.setUserName(name);
//record.setUserProfId(profId);
ofy().save().entity(record).now();
}
更改后如下所示:
@ApiMethod(name = "register")
public void registerDevice(@Named("regId") String regId, @Named("name") String name, @Named("profId") String profId) {
if (findRecord(regId) != null) {
log.info("Device " + regId + " already registered, skipping register");
return;
}
RegistrationRecord record = new RegistrationRecord();
record.setRegId(regId);
record.setUserName(name);
record.setUserProfId(profId);
ofy().save().entity(record).now();
}
添加这两个参数后,GCM 请求失败并出现以下错误:
com.google.api.client.googleapis.json.GoogleJsonResponseException: 404 Not Found
在我代码的这一行(在 AsyncTask
中)
regService.register(Globals.REG_ID,"Test","Test").execute();
但是当 "Test","Test" 像在原始教程中一样被删除时,它工作正常!
总之,当我添加自己的参数和我想要的字段时,我无法 post 到数据存储区。有什么建议么?
当您在 Google Cloud Endpoints 中引入新方法时,您必须执行以下操作:
- 将新版本上传到 App Engine
- 如果您更改了版本名称,则必须在 Developer Console 中将其设为默认版本
404表示没有这样的方法,所以我假设你还没有完成上述步骤之一。
如果您完成了上述步骤,只需使用 API Explorer
检查该方法是否有效
https://apis-explorer.appspot.com/apis-explorer/?base=https://appname.appspot.com/_ah/api
还有一件事。请记住检查参数顺序。根据我的经验,它宁愿是 (name, profId, regId)
,但我可能是错的:
regService.register("Test", "Test", Globals.REG_ID).execute();
我在完成示例 GCM 消息传递 (https://github.com/GoogleCloudPlatform/gradle-appengine-templates/tree/master/GcmEndpoints)
时遇到问题一切正常,直到我想向 RegistrationEndpoint
class 中的 registerDevice
方法添加额外的参数。我确定我之前添加了 @Named
。
更改前如下所示:
@ApiMethod(name = "register")
public void registerDevice(@Named("regId") String regId) {
if (findRecord(regId) != null) {
log.info("Device " + regId + " already registered, skipping register");
return;
}
RegistrationRecord record = new RegistrationRecord();
record.setRegId(regId);
//record.setUserName(name);
//record.setUserProfId(profId);
ofy().save().entity(record).now();
}
更改后如下所示:
@ApiMethod(name = "register")
public void registerDevice(@Named("regId") String regId, @Named("name") String name, @Named("profId") String profId) {
if (findRecord(regId) != null) {
log.info("Device " + regId + " already registered, skipping register");
return;
}
RegistrationRecord record = new RegistrationRecord();
record.setRegId(regId);
record.setUserName(name);
record.setUserProfId(profId);
ofy().save().entity(record).now();
}
添加这两个参数后,GCM 请求失败并出现以下错误:
com.google.api.client.googleapis.json.GoogleJsonResponseException: 404 Not Found
在我代码的这一行(在 AsyncTask
中)
regService.register(Globals.REG_ID,"Test","Test").execute();
但是当 "Test","Test" 像在原始教程中一样被删除时,它工作正常!
总之,当我添加自己的参数和我想要的字段时,我无法 post 到数据存储区。有什么建议么?
当您在 Google Cloud Endpoints 中引入新方法时,您必须执行以下操作:
- 将新版本上传到 App Engine
- 如果您更改了版本名称,则必须在 Developer Console 中将其设为默认版本
404表示没有这样的方法,所以我假设你还没有完成上述步骤之一。
如果您完成了上述步骤,只需使用 API Explorer
检查该方法是否有效https://apis-explorer.appspot.com/apis-explorer/?base=https://appname.appspot.com/_ah/api
还有一件事。请记住检查参数顺序。根据我的经验,它宁愿是 (name, profId, regId)
,但我可能是错的:
regService.register("Test", "Test", Globals.REG_ID).execute();