我有一个 Google 项目 credible-nation-130012,我在其中部署了一个用 Java 编写的应用程序。它使用AppEngine标准环境。唯一的内容是 Google 端点。您可以在 GitHub 上查看源代码:https://github.com/mhdirkse/least-common-multiplier .
虽然没有使用 Google 登录,但我想测试我的部署。为此,我访问了 https://credible-nation-130012.appspot.com/_ah/api/explorer使用火狐浏览器。我的API没有出现。我按 F12 获取开发者信息并看到以下错误:
跨源请求被阻止:同源策略不允许读取 https://accounts.google.com/ServiceLogin?service=ah&passive=true&continue=https://appengine.google.com/_ah/conflogin%3Fcontinue%3Dhttps://credible-nation-130012.appspot.com/_ah/api/discovery/v1/apis 处的远程资源。 (原因:缺少 CORS header “Access-Control-Allow-Origin”)。[了解更多] 跨源请求被阻止:同源策略不允许读取 https://accounts.google.com/ServiceLogin?service=ah&passive=true&continue=https://appengine.google.com/_ah/conflogin%3Fcontinue%3Dhttps://credible-nation-130012.appspot.com/_ah/api/discovery/v1/apis 处的远程资源。 (原因:CORS请求未成功)。[了解更多] 跨源请求被阻止:同源策略不允许读取 https://accounts.google.com/ServiceLogin?service=ah&passive=true&continue=https://appengine.google.com/_ah/conflogin%3Fcontinue%3Dhttps://credible-nation-130012.appspot.com/_ah/api/discovery/v1/apis 处的远程资源。 (原因:缺少 CORS header “Access-Control-Allow-Origin”)。[了解更多] 跨源请求被阻止:同源策略不允许读取 https://accounts.google.com/ServiceLogin?service=ah&passive=true&continue=https://appengine.google.com/_ah/conflogin%3Fcontinue%3Dhttps://credible-nation-130012.appspot.com/_ah/api/discovery/v1/apis 处的远程资源。 (原因:CORS请求未成功)。[了解更多]
然后我关闭了选项卡并访问了 console.cloud.google.com 进行登录。之后我的 API 出现在 https://credible-nation-130012.appspot.com/_ah/api/explorer它起作用了。
我猜测API资源管理器无法正确访问https://accounts.google.com 。它期望返回 header Access-Control-Allow-Origin 但该 header 不存在。这与我的应用程序有什么关系,还是 API 资源管理器中的错误?或者这种行为是谷歌故意的吗?欢迎任何帮助。
谨致问候,
马丁·德克斯
顺便说一句:我正在为工作申请演示这个项目。如果我在这个问题上得到帮助,我会在 GitHub 上明确说明并与可能的雇主沟通。
最佳答案
问题可能出在您的 web.xml
中。您已为所有 URL 设置了管理员身份验证约束,API Explorer 需要访问特定 URL 路径 /_ah/api/discovery/v1/apis
(及其下的路径)才能工作。删除约束或放松约束以排除 /_ah/api
。
关于java - 当我未登录时,Google 的 API 资源管理器不适用于我的 Google 部署,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52393800/