java - 在 Android Studio 中构建 Google Endpoints 后端时出现 403 禁止错误

标签 java android-studio google-cloud-endpoints httpexception

这是我第一次尝试在 Android Studio 项目中使用 GAE 端点连接。因此,我只是按照 Google ( https://cloud.google.com/tools/android-studio/app_engine/) 提供的说明进行操作。但是每次我尝试构建或运行后端模块时都会收到 403 错误。这是消息:

Error:Execution failed for task ':backend:appengineEndpointsGetClientLibs'.
> There was an error running endpoints command get-client-lib: 403 Forbidden
  <!DOCTYPE html>
<html lang=en>
  <meta charset=utf-8>
  <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
  <title>Error 403 (Forbidden)!!1</title>
  <style>
    *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}
  </style>
  <a href=//www.google.com/><span id=logo aria-label=Google></span></a>
  <p><b>403.</b> <ins>That’s an error.</ins>
  <p>Your client does not have permission to get URL <code>/_ah/api/discovery/v1/apis/generate/rest</code> from this server.  <ins>That’s all we know.</ins>

通常我可以通过在“设置”中启用代理来抑制此类问题。但是对于这个错误,在谷歌搜索了 3 天并尝试了我脑海中闪过的所有解决方案之后,没有任何改变。有人遇到过同样的错误吗?或者知道解决方案/建议?

编辑 我正在运行带有示例 MyBean 和 MyEndpoint 类的模板端点项目,没有任何更改。这是相关的 build.gradle 文件:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.google.appengine:gradle-appengine-plugin:1.9.18'
    }
}

repositories {
    mavenCentral();
}

apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'appengine'

sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7

dependencies {
    appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.18'
    compile 'com.google.appengine:appengine-endpoints:1.9.18'
    compile 'com.google.appengine:appengine-endpoints-deps:1.9.18'
    compile 'javax.servlet:servlet-api:2.5'
}

appengine {
    downloadSdk = true
    appcfg {
        oauth2 = true
    }
    endpoints {
        getClientLibsOnBuild = true
        getDiscoveryDocsOnBuild = true
    }
}

最佳答案

谷歌阻止包括伊朗在内的一些国家的人访问 http://developer.google.comhttp://apis.google.com , 所以你遇到了问题。

出于隐私可移植性和其他几个方面的考虑,您无论如何都应该避免使用 Google App Engine

Portability concerns

Developers worry that the applications will not be portable from App Engine and fear being locked into the technology. In response, there are a number of projects to create open-source back-ends for the various proprietary/closed APIs of app engine, especially the datastore. AppScale, CapeDwarf and TyphoonAE are a few of the open source efforts.

https://en.wikipedia.org/wiki/Google_App_Engine#Portability_concerns

您可以使用这些替代方案。

关于java - 在 Android Studio 中构建 Google Endpoints 后端时出现 403 禁止错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36234113/

相关文章:

Java打印票

java - 每 'when' 步执行 Action Spock

java - 关闭触摸外部的弹出窗口

java - 如何添加向右滑动打开抽屉导航

java - 谷歌端点

android - 我应该在 Android 客户端中验证 OAuth2 token ,还是 App Engine 本身会根据传递给后端 API 的凭据对用户进行身份验证?

java - BufferedReader 性能低下

Java:使函数返回正整数而不是负整数

java - 如何在android上使用AccessibilityService获取屏幕上的View对象?

google-app-engine - 谷歌云端点稳定性?