我正在尝试为服务器端应用实施Google登录。在我的app引擎应用程序中。我正在使用Eclipse Luna,我已经从这个链接中学习了教程:https://developers.google.com/identity/sign-in/web/server-side-flow#step_7_exchange_the_authorization_code_for_an_access_token
我在构建路径中添加了以下jar文件:
google-api-client-jackson2-1.16.0-rc.jar
,appengine-gcs-client-0.5.jar
,
和我从maven repo下载的google-api-client-1.8.0-beta.jar
。
我有一个错误,我不知道还有什么办法来解决它。我在我的代码中用双星号标记了它。
错误消息为:The type com.google.api.client.json.JsonFactory cannot be resolved. It is indirectly referenced from required .class files.
我在StackOverflow上搜索过类似的问题,但我找不到解决这个问题的答案。
拜托,有人可以怜悯我并帮助我!此功能延迟了我的部署。提前谢谢。
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// Set path to the Web application client_secret_*.json file you downloaded from the
// Google Developers Console: https://console.developers.google.com/apis/credentials?project=_
// You can also find your Web application client ID and client secret from the
// console and specify them directly when you create the GoogleAuthorizationCodeTokenRequest
// object.
ServletContext context = getServletContext();
String CLIENT_SECRET_FILE = context.getRealPath("/WEB-INF/client/client_secret.json");
// Exchange auth code for access token
GoogleClientSecrets clientSecrets =
**GoogleClientSecrets.load(
JacksonFactory.getDefaultInstance(), new FileReader(CLIENT_SECRET_FILE));**
GoogleTokenResponse tokenResponse =
new GoogleAuthorizationCodeTokenRequest(
new NetHttpTransport(),
JacksonFactory.getDefaultInstance(),
"https://www.googleapis.com/oauth2/v4/token",
clientSecrets.getDetails().getClientId(),
clientSecrets.getDetails().getClientSecret(),
authCode,
REDIRECT_URI) // Specify the same redirect URI that you use with your web
// app. If you don't have a web version of your app, you can
// specify an empty string.
.execute();
String accessToken = tokenResponse.getAccessToken();
// Use access token to call API
GoogleCredential credential = new GoogleCredential().setAccessToken(accessToken);
Drive drive =
new Drive.Builder(new NetHttpTransport(), JacksonFactory.getDefaultInstance(), credential)
.setApplicationName("Auth Code Exchange Demo")
.build();
File file = drive.files().get("appfolder").execute();
// Get profile info from ID token
GoogleIdToken idToken = tokenResponse.parseIdToken();
GoogleIdToken.Payload payload = idToken.getPayload();
String userId = payload.getSubject(); // Use this value as a key to identify a user.
String email = payload.getEmail();
boolean emailVerified = Boolean.valueOf(payload.getEmailVerified());
String name = (String) payload.get("name");
String pictureUrl = (String) payload.get("picture");
String locale = (String) payload.get("locale");
String familyName = (String) payload.get("family_name");
String givenName = (String) payload.get("given_name");
}
答案 0 :(得分:0)
我假设你已经下载了dependencies但你没有使用maven,我认为问题是Maven自动解决了间接依赖关系,但你还没有解决它们。
如果你想使用google的jsonFactory,你需要http-client库。
您可以在此处下载:
http://repo2.maven.org/maven2/com/google/http-client/google-http-client-jackson/