【发布时间】:2016-05-30 14:41:34
【问题描述】:
我有一个使用 Google API JavaScript 客户端库调用多个 App Engine Endpoints 的 Web 应用程序。
按照 Google (https://developers.google.com/api-client-library/javascript/features/promises#using-promises) 的建议,我目前正在将此应用程序从回调模式更改为承诺模式,但我遇到了问题。请注意,该应用在回调模式下运行良好。
我对 promises 模式的问题是在调用请求方法时找到正确的路径参数:
JavaScrit 代码:
var params = {'webSafeKeyParent’: ‘neN4fm15xW52b2ljZXMtb19saW5lmlYLEglBY1NFwpRpdHkYgICAgQj97AoM’};
gapi.client.request({
'path': 'https://myappenginename.appspot.com/_ah/api/customerApi/v1/?????????',
'params': params
}).then(function(response) {
// Handle response
}, function(reason) {
// Handle error
});
“customerApi”中的端点定义:
@ApiMethod(
name = "listByParent",
path = "customerByParent/{webSafeKeyParent}",
httpMethod = ApiMethod.HttpMethod.GET,
scopes = {Constants.EMAIL_SCOPE},
clientIds = {Constants.WEB_CLIENT_ID, com.google.api.server.spi.Constant.API_EXPLORER_CLIENT_ID},
audiences = {Constants.ANDROID_AUDIENCE})
public List<Customer> listByParent(final User user, @Named("webSafeKeyParent") final String webSafeKeyParent, @Nullable @Named("cursor") String cursor, @Nullable @Named("limit") Integer limit) throws UnauthorizedException {
对于我的少数端点,它通过在 JavaScript 请求方法的路径参数中包含 @ApiMethod 注释中声明的“路径”和“名称”的值来工作。
即对于上述端点,以下路径有效: https://myappenginename.appspot.com/_ah/api/customerApi/v1/customerByParent/listByParent
奇怪的是,这不适用于某些其他同类端点。我收到 404 HTTP 错误或 503 错误。
当您使用 APIs Explorer 查询端点但没有成功时,我也尝试使用“请求”下显示的路径......
是否有关于如何使用 Google API JavaScript 客户端库调用 App Engine Endpoints 的详细文档?我还没有找到。您有什么建议可以分享吗?
提前致谢
【问题讨论】:
标签: google-app-engine google-cloud-endpoints