[英]Calling app engine API's in a phonegap application
我希望在我的phonegap應用程序中執行API方法,以從數據存儲中檢索所有條目。 我已經在三星S4上對其進行了測試,似乎在控制台中未發現任何錯誤或任何東西,數據存儲區的日志表明沒有嘗試從數據存儲區檢索數據。
我將在下面發布我的base.js文件,該文件是假定執行API調用的函數。
我一直在遵循Google創建的本指南來實現此目的。 該方法用於POST而不是GET,因為根據我所遵循的另一教程,您必須通過post方法而不是get方法來請求數據。
var requestData = {};
google.appengine.CMS.client.getCalls = function() {
gapi.client.call.queryCalls(requestData).execute(function(resp) {
if (!resp.code) {
resp.calls = resp.calls || [];
var result = "";
for (var i=0;i<resp.calls.length;i++) {
result = result+ resp.calls[i].callId+ " : " + resp.calls[i].patientName+ " : " + resp.calls[i].doctor+ " : " + "<br/>" + resp.calls[i].address1+ " : " + resp.calls[i].address2+ " : " + resp.calls[i].address3+ " : " + "<br/>" + resp.calls[i].postCode + " : " + resp.calls[i].patientLocation+ " : " + resp.calls[i].symptoms+ " : " + "<br/>" + resp.calls[i].contactNumber+ " : " + resp.calls[i].callDateTime+ " : " + resp.calls[i].currentStatus+ "<br/>";
}
return result;
google.appengine.CMS.client.print(resp);
}
});
};
/**
* Enables the button callbacks in the UI.
*/
google.appengine.CMS.client.enableButtons = function() {
var ListCalls = document.querySelector('#listCalls');
ListCalls.addEventListener('click', google.appengine.CMS.client.getCalls);
};
/**
* Initializes the application.
* @param {string} apiRoot Root of the API's path.
*/
var apiRoot = 'generic root';
google.appengine.CMS.client.init = function(apiRoot) {
// Loads the OAuth and helloworld APIs asynchronously, and triggers login
// when they have completed.
var apisToLoad;
var callback = function() {
if (--apisToLoad == 0) {
google.appengine.CMS.client.enableButtons();
}
};
apisToLoad = 1; // must match number of calls to gapi.client.load()
gapi.client.load('call', 'v1', callback, apiRoot);
};
如果您使用打包的phonegapp應用程序(顯示localhost的Web視圖),則需要:
我建議您使用一個直接指向* .appspot.com上的頁面的phonegap應用程序,而不是將其復制到該應用程序上:
[2] https://cloud.google.com/appengine/docs/java/endpoints/getstarted/clients/js/client_ui
代替
<script>
function init() {
google.appengine.samples.hello.init('//' + window.location.host + '/_ah/api');
}
</script>
<script src="https://apis.google.com/js/client.js?onload=init"></script>
采用
<script>
function init() {
google.appengine.samples.hello.init('https://youappid.appspot.com/_ah/api');
}
</script>
<script src="https://apis.google.com/js/client.js?onload=init"></script>
[3] https://cloud.google.com/appengine/docs/java/endpoints/consume_js
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.