我正在尝试以下api调用我的GAE Cloud Endpoint:
gapi.client.myapp.foo.update({
"value": "foobar",
"key": "keyvaluefromlistoperation"
}).execute(function(resp) {
console.log(resp);
});
以下内容作出回应:
[
{
"error": {
"code": 400,
"message": "Bad Request",
"data": [
{
"domain": "usageLimits",
"reason": "keyInvalid",
"message": "Bad Request"
}
]
},
"id": "gapiRpc"
}
]
注意,在此调用之前,我已经过身份验证,插入了几个foo对象,然后调用list以将它们返回给客户端。 api的资源管理器更新调用工作正常,并运行下面的jQuery代码段工作正常。有什么建议?或者我只是在实验性的土地上。
var token = gapi.auth.getToken();
$.ajax({
type:"POST",
beforeSend: function (request) {
request.setRequestHeader("Content-Type","application/json");
request.setRequestHeader("Authorization", token.token_type+" "+token.access_token);
},
url: "https://myappid.appspot.com/_ah/api/myapp/v1/foo/update",
data:JSON.stringify({
"value": "foobar",
"key": "keyvaluefromlistoperation"
}),
processData: false,
dataType: "json",
success: function(msg) {
console.log(msg);
},
failure: function(msg) {
console.log(msg);
}
});
这是Java代码:
@Api(
name = "myapp",
description = "This is the myapp rest interface",
scopes = {"https://www.googleapis.com/auth/userinfo.email"},
version = "v1",
clientIds = {Ids.WEB_CLIENT_ID}
)
public class FooV1 {
private static PersistenceManager getPersistenceManager() {
return PMF.get().getPersistenceManager();
}
@ApiMethod(
name = "foo.update",
httpMethod = HttpMethod.POST
)
public Foo update(Foo foo, User user) throws OAuthRequestException, IOException, UnauthorizedUpdateException {
PersistenceManager pm = PMF.get().getPersistenceManager();
if (user != null) {
try {
Foo f = pm.getObjectById(Foo.class, foo.getId());
if ( Security.isUpdateAuthorized(f, user) ) {
if( foo.getValue() != null ) f.setValue(foo.getValue());
} else {
throw new UnauthorizedUpdateException("");
}
} finally {
pm.close();
}
} else {
throw new OAuthRequestException("Invalid user.");
}
return foo;
}
}
答案 0 :(得分:9)
我遇到了同样的问题。显然,一旦部署到GAE,您就无法使用“key”作为字段。在当地,它运作良好。