我正在尝试验证并获取用户的个人资料数据,但出现以下错误,请提出建议。
// Generate the URL to which we will direct users
String authorizeUrl = new GoogleAuthorizationRequestUrl(CLIENT_ID,
CALLBACK_URL, SCOPE).build();
System.out.println("Paste this url in your browser: " + authorizeUrl);
// Wait for the authorization code
System.out.println("Type the code you received here: ");
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String authorizationCode = in.readLine();
// Exchange for an access and refresh token
GoogleAuthorizationCodeGrant authRequest = new GoogleAuthorizationCodeGrant(
TRANSPORT, JSON_FACTORY, CLIENT_ID, CLIENT_SECRET,
authorizationCode, CALLBACK_URL);
authRequest.useBasicAuthorization = false;
AccessTokenResponse authResponse = authRequest.execute();
String accessToken = authResponse.accessToken;
GoogleAccessProtectedResource requestInitializer = new GoogleAccessProtectedResource(
accessToken, TRANSPORT, JSON_FACTORY, CLIENT_ID, CLIENT_SECRET,
authResponse.refreshToken);
// Set up the main Google+ class
Plus plus = new Plus(TRANSPORT, requestInitializer,JSON_FACTORY);
// Make a request to access your profile and display it to console
Person profile = plus.people.get("me").execute();
System.out.println("ID: " + profile.getId());
System.out.println("Name: " + profile.getDisplayName());
System.out.println("Image URL: " + profile.getImage().getUrl());
System.out.println("Profile URL: " + profile.getUrl());
错误是:-
线程“主”java.lang.IllegalAccessError 中的异常:试图从 com.google.api.client 类 com.google.api.client.googleapis.MethodOverride 访问字段 com.google.api.client.http.HttpRequest.method .googleapis.MethodOverride.overrideThisMethod(MethodOverride.java:99) 在 com.google.api.client.googleapis.MethodOverride.intercept(MethodOverride.java:87) 在 com.google.api.services.plus.ApiClient.buildHttpRequest(ApiClient .java:251) 在 com.google.api.services.plus.Plus$RemoteRequest.execute(Plus.java:1055) 在 com.google.api.services.plus.Plus$People$Get.executeUnparsed(Plus.java :991) 在 com.google.api.services.plus.Plus$People$Get.execute(Plus.java:976) 在 com.googleplus.test.TestAuth2.main(TestAuth2.java:64)