gpt4 book ai didi

java - 在java错误中从google plus获取个人资料信息

转载 作者:行者123 更新时间:2023-12-02 08:40:18 25 4
gpt4 key购买 nike

我正在尝试验证并获取用户的个人资料数据,但出现以下错误,请提出建议。

// 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());

错误是:-

线程“main”中出现异常 java.lang.IllegalAccessError:尝试从类 com.google.api.client.googleapis.MethodOverride 访问字段 com.google.api.client.http.HttpRequest.method 在 com.google.api.client.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)

最佳答案

您是否尝试过使用this starter project中的代码?

关于java - 在java错误中从google plus获取个人资料信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13350116/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com