我有一个Cloud Endpoints
方法看起来像这样:
//HTTP POST
@ApiMethod(name = "hylyts.insert")
public Hylyt insertHylyt(@Named("url") String url, Hylyt hylyt, User user)
throws OAuthRequestException{
log.info("Trying to save hylyt '"+hylyt+"' with id '"+hylyt.getId());
if (user== null) throw new OAuthRequestException("Your token is no good here.");
hylyt.setArticle(getArticleKey(url, user));
ofy().save().entity(hylyt);
return hylyt;
}
我称它为Javascript Client Library
使用这个:
gapi.client.hylytit.hylyts.insert({PARAMS}).execute(callback);
现在,如果我构造{PARAMS}
如建议的docs https://developers.google.com/api-client-library/javascript/dev/dev_jscript#ExampleGoogleCloudStorage(第二个例子),
{
'url': url,
'resource': {
'hylyt': {
'contentType': 'application/json',
'data': hylyt
}
}
}
我在端点中得到一个空对象(更不用说这个库的全部目的是使这些调用变得简单,而这个结构显然违反了这一点)。
当我构建{PARAMS}
as these https://stackoverflow.com/a/17458007/1720014 answers https://stackoverflow.com/questions/19804951/google-cloud-endpoints-making-calls-with-js-client-passing-params-and-json-bo/19809245#19809245建议,
{
'url': url,
'resource': hylyt
}
我再次在端点中得到一个空对象。正确的语法是这样的:
{
'url': url,
'id': hylyt.id
'text': hylyt.text
}
这让我大吃一惊。难道我做的这一切都是错的吗?这是一个错误吗?难道这只是因为gapi
也正在通过auth token
在后台?
是的,我可以使用request
语法,但是,再说一次,如果它和制作一样复杂,为什么还要使用该库XHR
是纯javascript吗?如果谷歌在文档中解释,我不会介意复杂性why事情正在发生。但文档中解释说,只是说使用这些方法,并且身份验证、CORS 和 XHR 魔法将在幕后发生。