gpt4 book ai didi

java - 向 Cloud Endpoint 添加参数会导致 404 GoogleJsonResponseException

转载 作者:行者123 更新时间:2023-12-01 12:04:13 25 4
gpt4 key购买 nike

我在完成示例 GCM 消息传递 ( https://github.com/GoogleCloudPlatform/gradle-appengine-templates/tree/master/GcmEndpoints ) 时遇到问题

一切工作正常,直到我想向 RegistrationEndpoint 类中的 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”时,它工作正常!

总之,当我使用所需的字段添加自己的参数时,我无法发布到数据存储区。有什么建议么?

最佳答案

当您在 Google Cloud Endpoints 中引入新方法时,您必须执行以下操作:

  1. 将新版本上传到 App Engine
  2. 如果您更改了版本名称,则必须在开发者控制台中将其设为默认版本

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(); 

关于java - 向 Cloud Endpoint 添加参数会导致 404 GoogleJsonResponseException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27762076/

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