java - App Engine Java Servlet 中收到 OAuthRequestException

标签 java google-app-engine google-cloud-endpoints google-cloud-platform google-oauth

我正在尝试访问 Java Servlet 中的 App Engine 用户个人资料,如下所示。

String scope = "https://www.googleapis.com/auth/userinfo.email profile";
OAuthService oathService = OAuthServiceFactory.getOAuthService();
User user = oathService.getCurrentUser(scope);

每当访问用户数据时,都会抛出 OAuthRequestException。相同的代码可以在开发模式下运行,但不能在部署模式下运行。

我不明白为什么会抛出错误。据我了解,所需的权限是可用的,如在线文档中所述(我猜!)。

最佳答案

当请求不是有效的 OAuth 请求时,将引发 OAuthRequestException。 这里有一些例子link ,例如:

   String scope = "https://www.googleapis.com/auth/userinfo.email";
   try {
    user = oauth.getCurrentUser(scope);
  } catch (OAuthRequestException e) {
    log("Impossible to authenticate the request from the image resizer, oauth request exception: "
        + e.getMessage());
    resp.setStatus(HttpStatusCodes.STATUS_CODE_UNAUTHORIZED);
    return;
  }

关于java - App Engine Java Servlet 中收到 OAuthRequestException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35324111/

相关文章:

java - Android 共享首选项未通过提交/应用/清除保存

java - Lauch4j .ini文件指定jre路径

Google Cloud Endpoint 上用于 API key 授权的 Java 注释?

java - Google 应用引擎 (GAE) 和 Android

java - 正则表达式无序匹配

Java 小程序 : How to invoke/access javascript variable of web page from applet?

java - NoClassDefFoundError : com/google/appengine/api/urlfetch/ResponseTooLargeException

google-app-engine - 如何创建 GAE 数据存储的本地副本?

java - GAE Jersey RESTful 服务 POST JSON

java - Google App Engine Connected Android (Eclipse) 设备端点错误