简体   繁体   English

从Javascript库加载我的自定义Google API(远程项目)

[英]Load my Custom Google API from Javascript Library (remote projects)

I'm trying to load my custom Google Api (Appengine Endpoints) to my frontend project but I receive TypeError: gapi.client.myCustomApi is undefined . 我正在尝试将自定义Google Api(Appengine端点)加载到我的前端项目但我收到TypeError: gapi.client.myCustomApi is undefined

I have two projects in Appengine (Frontend and backend project). 我在Appengine有两个项目 (前端和后端项目)。 I have generated the Api Key from the Backend Project . 我从后端项目生成了Api Key So, I'm following this tutorial: https://cloud.google.com/appengine/docs/python/endpoints/consume_js 所以,我正在关注本教程: https//cloud.google.com/appengine/docs/python/endpoints/consume_js

This is my index.html in code in Frontend project: 这是我在前端项目中的代码中的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>

Please reply if anyone can help me. 请回复是否有人可以帮助我。 Thanks! 谢谢!

EDIT1: EDIT1:

I have used gapi.client.request for testing, and it works perfect. 我已经使用gapi.client.request进行测试,它完美无缺。 gapi.client.load doesn't work yet. 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); 
});

I have fixed it! 我修好了! Was my mistake. 是我的错 Just to need to put "v1.0" in version field. 只需要在版本字段中输入“v1.0”。 So, for example: 所以,例如:

<script>
function loadGapi(){
gapi.client.setApiKey('AIzaSyBvg9bSWGUHhAO-TPIww3KuKhJqC2_BAFk');
gapi.client.load('myCustomApi', 'v1.0', 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM