Tôi đang làm việc với API phân tích google trong Java. Tôi có một mã lấy mã thông báo truy cập từ mã thông báo làm mới. Chúng tôi lưu trữ mã thông báo làm mới trong cơ sở dữ liệu và trong khi yêu cầu, truy xuất mã thông báo truy cập.Google Analytics: Nhận mã thông báo truy cập từ mã thông báo làm mới
Sau khi thay đổi mật khẩu, mã thông báo yêu cầu của chúng tôi không hợp lệ. Vì vậy, tôi tạo ra một refreshtoken mới bằng cách duyệt url (https://developers.google.com/oauthplayground) và làm theo hướng dẫn. Tôi nhận được mã thông báo làm mới mới. Bây giờ, khi tôi thực thi mã để lấy mã thông báo truy cập, nó ném ngoại lệ con trỏ null. Dưới đây là các mã:
RefreshTokenRequest request = new GoogleRefreshTokenRequest(HTTP_TRANSPORT, JSON_FACTORY, refreshToken,
this.clientId, this.clientSecret);
TokenResponse response = request.execute();
Khi thực thi phương thức được gọi, nó ném ngoại lệ sau đây:
java.lang.NullPointerException
at com.google.api.client.repackaged.com.google.common.base.Preconditions.checkNotNull(Preconditions.java:191)
at com.google.api.client.util.Preconditions.checkNotNull(Preconditions.java:127)
at com.google.api.client.json.jackson2.JacksonFactory.createJsonParser(JacksonFactory.java:96)
at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:85)
at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:81)
at com.google.api.client.auth.oauth2.TokenResponseException.from(TokenResponseException.java:88)
at com.google.api.client.auth.oauth2.TokenRequest.executeUnparsed(TokenRequest.java:287)
at com.google.api.client.googleapis.auth.oauth2.GoogleRefreshTokenRequest.execute(GoogleRefreshTokenRequest.java:125)
at com.google.api.client.googleapis.auth.oauth2.GoogleRefreshTokenRequest.execute(GoogleRefreshTokenRequest.java:75)
at GARTest.main(GARTest.java:22)
bất cứ ai có thể vui lòng chỉ nơi tôi làm sai? Tôi có thể nhận mã thông báo truy cập từ giao diện người dùng google oAuth.
Tôi e rằng đây là sự cố mở đối với thư viện java GoogleApi: https://github.com/google/google-api-java-client/issues/932 vui lòng chia sẻ nếu bạn có bất kỳ giải pháp nào. – Artem
Bạn không nên sử dụng Oauthplayground để có được một RefreshToken, đây phải là một phần của mã của bạn. Ngoài ra, thay đổi mật khẩu sẽ không ảnh hưởng đến Oauth2 RefreshToken, đó là toàn bộ điểm của OAuth. – DaImTo