本文整理匯總了Java中com.google.api.client.auth.oauth2.Credential.getRefreshToken方法的典型用法代碼示例。如果您正苦於以下問題:Java Credential.getRefreshToken方法的具體用法?Java Credential.getRefreshToken怎麽用?Java Credential.getRefreshToken使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.api.client.auth.oauth2.Credential
的用法示例。
在下文中一共展示了Credential.getRefreshToken方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: store
import com.google.api.client.auth.oauth2.Credential; //導入方法依賴的package包/類
@Override
public void store(String userId, Credential credential) throws IOException {
Log.i(BnConstants.TAG, "Storing credential for userId ".concat(userId));
Log.i(BnConstants.TAG, "Access Token = ".concat(credential.getAccessToken()));
SharedPreferences.Editor editor = prefs.edit();
editor.putString(userId + ACCESS_TOKEN,credential.getAccessToken());
if (credential.getExpirationTimeMilliseconds()!=null) {
editor.putLong(userId + EXPIRES_IN,credential.getExpirationTimeMilliseconds());
}
if (credential.getRefreshToken()!=null) {
editor.putString(userId + REFRESH_TOKEN,credential.getRefreshToken());
}
editor.commit();
}
示例2: getNewOAuth2Credential
import com.google.api.client.auth.oauth2.Credential; //導入方法依賴的package包/類
/**
* Get New Credentials from the user from the command line OAuth2 dance.
*/
private Credential getNewOAuth2Credential() throws OAuthException {
GoogleAuthorizationCodeFlow authorizationFlow = getAuthorizationFlow();
String authorizeUrl =
authorizationFlow.newAuthorizationUrl().setRedirectUri(CALLBACK_URL).build();
System.out.println("\n**ACTION REQUIRED** Paste this url in your browser"
+ " and authenticate using your **AdWords Admin Email**: \n" + authorizeUrl);
// Wait for the authorization code.
System.out.println("\nType the code you received on the web page here: ");
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String authorizationCode = reader.readLine();
// Authorize the OAuth2 token.
GoogleAuthorizationCodeTokenRequest tokenRequest =
authorizationFlow.newTokenRequest(authorizationCode);
tokenRequest.setRedirectUri(CALLBACK_URL);
GoogleTokenResponse tokenResponse = tokenRequest.execute();
// Create the credential.
Credential credential =
new GoogleCredential.Builder()
.setClientSecrets(clientId, clientSecret)
.setJsonFactory(new JacksonFactory())
.setTransport(new NetHttpTransport())
.build()
.setFromTokenResponse(tokenResponse);
// Get refresh token and prompt to save in properties file
refreshToken = credential.getRefreshToken();
System.out.println("\n**ACTION REQUIRED** Put the following line in your properties file to"
+ " avoid OAuth authentication next time.");
System.out.printf("refreshToken=%s\n\n", refreshToken);
System.out.println("Then press enter to continue...");
reader.readLine();
return credential;
} catch (IOException e) {
throw new OAuthException("An error occured obtaining the OAuth2Credential", e.getCause());
}
}