本文整理汇总了Java中com.google.api.client.util.store.DataStore.set方法的典型用法代码示例。如果您正苦于以下问题:Java DataStore.set方法的具体用法?Java DataStore.set怎么用?Java DataStore.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.api.client.util.store.DataStore
的用法示例。
在下文中一共展示了DataStore.set方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: storeOAuth2TokenData
import com.google.api.client.util.store.DataStore; //导入方法依赖的package包/类
/**
* Stores the given OAuth 2 token response within a file data store.
* The stored token response can then retrieved using the getOAuth2TokenDataFromStore method.
*
* @param storageId a string object that is used to store the token response
* @param tokenResponse the token response containing the OAuth 2 token information.
* @return If the token response was stored or not.
*/
public Boolean storeOAuth2TokenData(String storageId, TokenResponse tokenResponse) {
Boolean wasStored = false;
try {
File oauth2StorageFolder = new File(this.context.getFilesDir(),"oauth2StorageFolder");
oauth2StorageFolder.mkdirs();
FileDataStoreFactory fileDataStoreFactory = new FileDataStoreFactory(oauth2StorageFolder);
DataStore<StoredCredential> storedCredentialDataStore = fileDataStoreFactory.getDataStore(storageId);
Credential oauth2Credential = new Credential(BearerToken.authorizationHeaderAccessMethod()).setFromTokenResponse(
tokenResponse);
StoredCredential storedOAuth2Credential = new StoredCredential(oauth2Credential);
storedCredentialDataStore.set(storageId,storedOAuth2Credential);
wasStored = true;
} catch ( Exception exception ) {
logInfo("Exception storing OAuth2TokenData :" + exception.getLocalizedMessage());
}
return wasStored;
}
示例2: addCredentialToDataStore
import com.google.api.client.util.store.DataStore; //导入方法依赖的package包/类
private void addCredentialToDataStore(File dataStoreDir, StoredCredential credential) throws IOException {
FileDataStoreFactory dataStoreFactory = new FileDataStoreFactory(dataStoreDir);
DataStore<StoredCredential> dataStore = dataStoreFactory.getDataStore(DEFAULT_DATA_STORE_ID);
dataStore.set("user", credential);
}