App Engine Java Servlet 中收到 OAuthRequestException
OAuthRequestException received in App Engine Java Servlet
我正在尝试访问 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;
}
错误已通过调用 UserService
获取当前 User
解决。但是,这不适用于开发模式。可能 Google App Engine 团队的人可以解释一下!
UserService userService = UserServiceFactory.getUserService();
user = userService.getCurrentUser();
if (user == null) {
res.sendRedirect(userService.createLoginURL(req.getRequestURI()));
return;
}
我正在尝试访问 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;
}
错误已通过调用 UserService
获取当前 User
解决。但是,这不适用于开发模式。可能 Google App Engine 团队的人可以解释一下!
UserService userService = UserServiceFactory.getUserService();
user = userService.getCurrentUser();
if (user == null) {
res.sendRedirect(userService.createLoginURL(req.getRequestURI()));
return;
}