我正在尝试将我的自定义 Google Api(Appengine 端点)加载到我的前端项目中,但我收到了TypeError: gapi.client.myCustomApi is undefined
.
我在 Appengine 中有两个项目(前端和后端项目)。我已经从Backend Project生成了Api Key。所以,我正在关注本教程:https ://cloud.google.com/appengine/docs/python/endpoints/consume_js
这是我在前端项目代码中的index.html :
<script>
function loadGapi(){
gapi.client.setApiKey('AIzaSyBvg9bSWGUHhAO-TPIww3KuKhJqC2_BAFk');
gapi.client.load('myCustomApi', 'v1', function() {
gapi.client.myCustomApi.list().execute(function(resp) {
console.log(resp);
});
}, 'https://my-backend-project.appspot.com/_ah/api');
}
</script>
<script src="https://apis.google.com/js/client.js?onload=loadGapi"> </script>
如果有人可以帮助我,请回复。谢谢!
编辑1:
我已经使用gapi.client.request进行测试,并且效果很好。gapi.client.load 还没有工作。
gapi.client.request({
"path": "/myCustomApi/v1.0/list",
"root": "https://my-backend-project.appspot.com/_ah/api"
}).execute(function (response) {
console.log(response);
});