如何将Google应用程序端点与phonegap应用程序集成 [英] How Integrate Google app endpoints with a phonegap app

查看:117
本文介绍了如何将Google应用程序端点与phonegap应用程序集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在开发一个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 unknown What 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应用程序集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆