我正在尝试实现这个示例,
https://google-developers.appspot.com/drive/auth/web-server
但是没有找到以下类! Oauth2
,用户信息
static User getUserInfo(Credential credentials)
throws NoUserIdException {
Oauth2 userInfoService =
new Oauth2.Builder(new NetHttpTransport(), new JacksonFactory(), credentials).build();
Userinfo userInfo = null;
try {
userInfo = userInfoService.userinfo().get().execute();
} catch (IOException e) {
System.err.println("An error occurred: " + e);
}
if (userInfo != null && userInfo.getId() != null) {
return userInfo;
} else {
throw new NoUserIdException();
}
}
已找到所有其他类。我的构建路径 (Eclipse) 中有最新的 Drive 库。
这个例子有点困惑。我之前已经实现过 OAuth,但它太冗长且过于复杂。甚至不清楚用户被发送到 Google 进行身份验证的位置。
最佳答案
必须添加
https://developers.google.com/api-client-library/java/apis/oauth2/v2
Drive SDK 有 com.google.api.client.auth.oauth2
,但没有 com.google.api.services.oauth2
!去算算吧!
但它仍然不起作用。
Type mismatch: cannot convert from Userinfo to User
所以我必须将返回类型更改为 Userinfo。
关于java - GWT 中的 Google Drive 身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19119770/