我正在尝试访问 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/