问题描述
我一直在开发一个Phonegap客户端应用程序,我使用google端点创建所有的Web服务。
I have been developing a Phonegap client application and I create all the web services using google endpoints.
但我使用api有问题。在我的index.html我有这个脚本
But i'm having a problem using the api. In my index.html i have 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>
我想要做的变量myapi全局。
What I'm trying to do i'ts make the variable myapi global.
在另一个js文件中,我想在phonegap ondeviceready函数中使用myapi,像这样
In another js file, i want to use myapi in the phonegap ondeviceready function , i'ts something like this
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
myapi.items.insert({
'id' : 4,
'name' : 'item',
}).execute(function(resp) {
console.log(resp);
});
}
问题是,我不工作,是未知
我做错了什么?
我如何使用我的enpoints api使用phonegap
The problem is that i'ts not working, i't seams like myapi is unknownWhat i'm doing wrong?How can i use my enpoints api using phonegap
推荐答案
我解决问题!
这是一个范围变量的问题,另外phonegap onDeviceReady函数必须在init函数中调用。
It was a scope variable problem, in addition the phonegap onDeviceReady function must be call in the init function.
这个工作对我来说: / p>
This work for me:
<head><script>
function initGoogleApis() {
var ROOT = "https://myapitest.appspot.com/_ah/api";
gapi.client.load("myapitest", "v1", function() {
document.addEventListener("deviceready", onDeviceReady, false);
}, ROOT);
}
</script></head>
<script src="https://apis.google.com/js/client.js?onload=initGoogleApis"></script>
这篇关于如何将Google应用程序端点与phonegap应用程序集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!