I've been working on a Phonegap client application and have developed all the necessary web services using Google Endpoints.
However, I am facing an issue with using the API. In my index.html file, there is this script:
<head><script>
var myapi;
function initGoogleApis() {
var ROOT = "https://myapitest.appspot.com/_ah/api";
gapi.client.load("myapitest", "v1", function() {
myapi = gapi.client.ratemyday;
}, ROOT);
}
</script></head>
<script src="https://apis.google.com/js/client.js?onload=initGoogleApis"></script>
The goal is to declare the variable myapi as global.
In another JavaScript file, I intend to utilize myapi within the Phonegap ondeviceready function, which looks like this:
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
myapi.items.insert({
'id' : 4,
'name' : 'item',
}).execute(function(resp) {
console.log(resp);
});
}
The issue is that it doesn't seem to be functioning correctly, as myapi is not recognized. What could I be doing wrong? How can I effectively use my endpoints API with Phonegap?