I'm trying to load my custom Google Api (Appengine Endpoints) to my frontend project but I receive TypeError: gapi.client.myCustomApi is undefined
.
I have two projects in Appengine (Frontend and backend project). I have generated the Api Key from the Backend Project . So, I'm following this tutorial: https://cloud.google.com/appengine/docs/python/endpoints/consume_js
This is my index.html in code in Frontend project:
<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:
I have used gapi.client.request for testing, and it works perfect. gapi.client.load doesn't work yet.
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. 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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.