【发布时间】:2016-09-25 02:21:27
【问题描述】:
环境
我正在使用 Bootstrap JavaScript UI 和 Google SQL 数据存储运行 AppEngine Cloud Endpoints。
问题
当 Javascript 调用 gapi.client.load 时,它会得到 404。API Explorer 工作,JavaScript 在本地运行时工作......只是在尝试通过 JavaScript 加载 API 时失败。
这是 Chrome 中出现的错误:
GET https://MyAppID.appspot.com/_ah/api/discovery/v1/apis/myAP…%2Cversion%2CrootUrl%2CservicePath%2Cresources%2Cparameters%2Cmethods&pp=0 404 ()
zu @ cb=gapi.loaded_0:83
n @ cb=gapi.loaded_0:83C
u @ cb=gapi.loaded_0:83
(anonymous function) @ cb=gapi.loaded_0:84
g @ cb=gapi.loaded_0:55
c @ cb=gapi.loaded_0:46
然后是另一个“无法读取属性”异常,因为它在 API 中找不到它未加载的方法。
代码
我的 index.html 页面的代码:
function init()
{
apisToLoad = 2;
var callback = function()
{
if (--apisToLoad == 0)
{
signin(true, userAuthed);
}
}
gapi.client.load('oauth2', 'v2', callback);
//LOCALCHANGE (SWITCH BETWEEN LOCAL AND NOT)
gapi.client.load('myAPI', 'v1', callback, 'https://MyAppId.appspot.com/_ah/api');
//gapi.client.load('myAPI', 'v1', callback, 'http://localhost:8080/_ah/api');
}
我认为这是对的,所以我还要包含我的 appengine.xml:
<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<application>MyAppID</application>
<version>1</version>
<threadsafe>true</threadsafe>
<use-google-connector-j>true</use-google-connector-j>
<system-properties>
<property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
</system-properties>
</appengine-web-app>
还有我的 web.xml:
<?xml version="1.0" encoding="utf-8" standalone="no"?><web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>SystemServiceServlet</servlet-name>
<servlet-class>com.google.api.server.spi.SystemServiceServlet</servlet-class>
<init-param>
<param-name>services</param-name>
<param-value>com.lthoi.myAPI</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>SystemServiceServlet</servlet-name>
<url-pattern>/_ah/spi/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
如果有人能想到错误可能在其他任何地方,我很乐意粘贴其他文件。
【问题讨论】:
-
检查您的应用日志中是否有对
/_ah/spi/BackendService.getApiConfig或/_ah/spi/BackendService.logMessages的请求。如果有错误,您需要修复它们。
标签: javascript google-app-engine google-cloud-endpoints