使用OAuth2.0对具有访问令牌的用户进行身份验证但是 GoogleAuthorizationCodeTokenRequest 会返回新的访问令牌,但它会为getRefreshToken令牌返回null,以下是我的代码:
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY, CLIENT_ID, CLIENT_SECRET, SCOPES)
.setAccessType("offline")
.setApprovalPrompt("force").build();
String authorizeUrl =
flow.newAuthorizationUrl().setRedirectUri(CALLBACK_URI).build();
System.out.println("Paste this url in your browser: \n" + authorizeUrl + '\n');
GoogleAuthorizationCodeTokenRequest tokenRequest =
flow.newTokenRequest(dfaToken);
tokenRequest.setRedirectUri(CALLBACK_URI);
GoogleTokenResponse tokenResponse = tokenRequest.execute();
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(new NetHttpTransport())
.setJsonFactory(new JacksonFactory())
.setClientSecrets(CLIENT_ID, CLIENT_SECRET)
.build();
credential.setFromTokenResponse(tokenResponse);
System.out.println(credential.getAccessToken());
System.out.println(credential.getRefreshToken());
我们需要在项目中设置任何配置吗?