我希望在我的phonegap应用程序中执行API方法来检索数据存储区中的所有条目。我一直在三星S4上测试它,并且似乎无法在控制台中获得任何错误或任何内容,数据存储区的日志表明没有尝试从数据存储区检索数据。
我将在下面发布我的base.js文件,该文件是执行API调用的函数。
我一直关注Google创建的guide来实现这一点。根据我正在遵循的另一个教程,该方法用于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);
};
答案 0 :(得分:1)
如果您使用打包的phonegapp应用程序,显示localhost的webview,则需要:
我建议您使用直接指向* .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