本文整理汇总了Java中com.google.api.client.util.store.DataStore类的典型用法代码示例。如果您正苦于以下问题:Java DataStore类的具体用法?Java DataStore怎么用?Java DataStore使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DataStore类属于com.google.api.client.util.store包,在下文中一共展示了DataStore类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: authorize
import com.google.api.client.util.store.DataStore; //导入依赖的package包/类
/**
* Authorizes the installed application to access user's protected data.
*
* @param scopes list of scopes needed to run youtube upload.
* @param clientSecret the client secret from Google API console
* @param credentialDatastore name of the credential datastore to cache OAuth tokens
*/
public static Credential authorize(
Collection<String> scopes, String clientSecret, String credentialDatastore)
throws IOException {
// Load client secrets
GoogleClientSecrets clientSecrets =
GoogleClientSecrets.load(JSON_FACTORY, new StringReader(clientSecret));
// This creates the credentials datastore at ~/.oauth-credentials/${credentialDatastore}
FileDataStoreFactory fileDataStoreFactory =
new FileDataStoreFactory(new File(getCredentialsDirectory()));
DataStore<StoredCredential> datastore = fileDataStoreFactory.getDataStore(credentialDatastore);
GoogleAuthorizationCodeFlow flow =
new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, scopes)
.setCredentialDataStore(datastore)
.build();
// authorize
return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
}
示例2: loadCredential
import com.google.api.client.util.store.DataStore; //导入依赖的package包/类
private static Credential loadCredential(String userId, DataStore<StoredCredential> credentialDataStore)
throws IOException {
Credential credential = newCredential(userId, credentialDataStore);
if (credentialDataStore != null) {
StoredCredential stored = credentialDataStore.get(userId);
if (stored == null) {
return null;
}
credential.setAccessToken(stored.getAccessToken());
credential.setRefreshToken(stored.getRefreshToken());
credential.setExpirationTimeMilliseconds(stored.getExpirationTimeMilliseconds());
if (logger.isDebugEnabled()) {
logger.debug("Loaded credential");
logger.debug("device access token: {}", stored.getAccessToken());
logger.debug("device refresh_token: {}", stored.getRefreshToken());
logger.debug("device expires_in: {}", stored.getExpirationTimeMilliseconds());
}
}
return credential;
}
示例3: authorize
import com.google.api.client.util.store.DataStore; //导入依赖的package包/类
public static Credential authorize(List<String> scopes, String credentialDatastore) throws IOException {
Reader clientSecretReader = new InputStreamReader(Auth.class.getResourceAsStream("/client_secrets.json"));
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, clientSecretReader);
if (clientSecrets.getDetails().getClientId().startsWith("Enter")
|| clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) {
System.out.println(
"Enter Client ID and Secret from https://console.developers.google.com/project/_/apiui/credential "
+ "into src/main/resources/client_secrets.json");
System.exit(1);
}
FileDataStoreFactory fileDataStoreFactory = new FileDataStoreFactory(new File(System.getProperty("user.home") + "/" + CREDENTIALS_DIRECTORY));
DataStore<StoredCredential> datastore = fileDataStoreFactory.getDataStore(credentialDatastore);
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, scopes).setCredentialDataStore(datastore)
.build();
LocalServerReceiver localReceiver = new LocalServerReceiver.Builder().setPort(8080).build();
return new AuthorizationCodeInstalledApp(flow, localReceiver).authorize("user");
}
示例4: authorize
import com.google.api.client.util.store.DataStore; //导入依赖的package包/类
/**
* Perform the authorisation for the youtube account
*
* @param scopes {@linkplain List} of scopes to perform
* authorization
* @param credentailDataStore name of the credential datastore
*
* @return {@linkplain Credential} object which is used for Requests
*
* @throws IOException an error occurs during the authorisation.
*
* @since 1.0
*/
public static Credential authorize(List<String> scopes,
String credentailDataStore)
throws IOException {
final Reader reader = new InputStreamReader(Auth.class.
getResourceAsStream("/youtube.json"));
final GoogleClientSecrets secrets = GoogleClientSecrets.load(
JSON_FACTORY, reader);
final FileDataStoreFactory dataStoreFactory = new FileDataStoreFactory(
Paths.get(System
.getProperty("user.home") + "/" + CREDENTIALS_DIRECTORY).
toFile());
final DataStore<StoredCredential> dataStore = dataStoreFactory.
getDataStore(credentailDataStore);
final GoogleAuthorizationCodeFlow flow
= new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT,
JSON_FACTORY,
secrets, scopes).setCredentialDataStore(dataStore).
build();
final LocalServerReceiver receiver = new LocalServerReceiver.Builder().
setPort(8080).build();
return new AuthorizationCodeInstalledApp(flow, receiver).authorize(
config.userId());
}
示例5: authorize
import com.google.api.client.util.store.DataStore; //导入依赖的package包/类
public static Credential authorize(List<String> scopes, String credentialDatastore) throws IOException {
Reader clientSecretReader = new InputStreamReader(YTAuth.class.getResourceAsStream("/client_secrets.json"));
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, clientSecretReader);
if (clientSecrets.getDetails().getClientId().startsWith("Enter") || clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) {
System.out.println("Enter Client ID and Secret from https://code.google.com/apis/console/?api=youtube into src/main/resources/client_secres.json");
System.exit(1);
}
FileDataStoreFactory fileDataStoreFactory= new FileDataStoreFactory(new File(System.getProperty("user.home") + "/" + CREDENTIALS_DIRECTORY));
DataStore<StoredCredential> dataStore = fileDataStoreFactory.getDataStore(credentialDatastore);
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, scopes).setCredentialDataStore(dataStore).build();
LocalServerReceiver localReceiver = new LocalServerReceiver.Builder().setPort(8080).build();
return new AuthorizationCodeInstalledApp(flow, localReceiver).authorize("user");
}
示例6: authorize
import com.google.api.client.util.store.DataStore; //导入依赖的package包/类
static Credential authorize(String clientId, String clientSecret, String credentialsPath, String credentialStore,
HttpTransport httpTransport, JsonFactory jsonFactory) throws IOException {
GoogleClientSecrets.Details installedDetails = new GoogleClientSecrets.Details();
installedDetails.setClientId(clientId);
installedDetails.setClientSecret(clientSecret);
GoogleClientSecrets clientSecrets = new GoogleClientSecrets();
clientSecrets.setInstalled(installedDetails);
FileDataStoreFactory fileDataStoreFactory = new FileDataStoreFactory(new java.io.File(credentialsPath));
DataStore<StoredCredential> datastore = fileDataStoreFactory.getDataStore(credentialStore);
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, jsonFactory,
clientSecrets, Collections.singleton(DriveScopes.DRIVE_FILE))
.setCredentialDataStore(datastore)
.build();
return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
}
示例7: 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;
}
示例8: delete
import com.google.api.client.util.store.DataStore; //导入依赖的package包/类
public DataStore<V> delete( String key ) throws IOException {
if ( key == null ) {
return this;
} else {
this.lock.lock();
try {
this.keyValueMap.remove( key );
this.save();
} finally {
this.lock.unlock();
}
return this;
}
}
示例9: set
import com.google.api.client.util.store.DataStore; //导入依赖的package包/类
public final DataStore<V> set(String key, V value) throws IOException {
Preconditions.checkNotNull(key);
Preconditions.checkNotNull(value);
lock.lock();
try {
keyValueMap.put(key, IOUtils.serialize(value));
save();
} finally {
lock.unlock();
}
return this;
}
示例10: delete
import com.google.api.client.util.store.DataStore; //导入依赖的package包/类
public DataStore<V> delete(String key) throws IOException {
if (key == null) {
return this;
}
lock.lock();
try {
keyValueMap.remove(key);
save();
} finally {
lock.unlock();
}
return this;
}
示例11: clear
import com.google.api.client.util.store.DataStore; //导入依赖的package包/类
public final DataStore<V> clear() throws IOException {
lock.lock();
try {
keyValueMap.clear();
save();
} finally {
lock.unlock();
}
return this;
}
示例12: authorize
import com.google.api.client.util.store.DataStore; //导入依赖的package包/类
/**
* Authorizes the installed application to access user's protected data.
*
* @param scopes list of scopes needed to run youtube upload.
* @param credentialDatastore name of the credential datastore to cache OAuth tokens
*/
public static Credential authorize(List<String> scopes, String credentialDatastore) throws IOException {
// Load client secrets.
Reader clientSecretReader = new InputStreamReader(Authorizer.class.getResourceAsStream("/client_secrets.json"));
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, clientSecretReader);
// Checks that the defaults have been replaced (Default = "Enter X here").
if (clientSecrets.getDetails().getClientId().startsWith("Enter")
|| clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) {
System.out.println(
"Enter Client ID and Secret from https://code.google.com/apis/console/?api=youtube"
+ "into src/main/resources/client_secrets.json");
System.exit(1);
}
// This creates the credentials datastore at ~/.oauth-credentials/${credentialDatastore}
FileDataStoreFactory fileDataStoreFactory = new FileDataStoreFactory(new File(System.getProperty("user.home") + "/" + CREDENTIALS_DIRECTORY));
DataStore<StoredCredential> datastore = fileDataStoreFactory.getDataStore(credentialDatastore);
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, scopes).setCredentialDataStore(datastore)
.build();
// Build the local server and bind it to port 8080
LocalServerReceiver localReceiver = new LocalServerReceiver.Builder().setPort(8080).build();
// Authorize.
return new AuthorizationCodeInstalledApp(flow, localReceiver).authorize("user");
}
示例13: getStoredCredentialDataStore
import com.google.api.client.util.store.DataStore; //导入依赖的package包/类
private DataStore<StoredCredential> getStoredCredentialDataStore()
throws IOException {
File userHomeDir = getUserHomeDir();
File mailimporter = new File(userHomeDir, ".mailimporter");
FileDataStoreFactory dataStoreFactory =
new FileDataStoreFactory(mailimporter);
return dataStoreFactory.getDataStore("credentials");
}
示例14: initializeAuthorizationFlow
import com.google.api.client.util.store.DataStore; //导入依赖的package包/类
private AuthorizationCodeFlow initializeAuthorizationFlow() throws IOException {
FileDataStoreFactory fileDataStoreFactory = new FileDataStoreFactory(new File(System.getProperty("user.home") + "/.knbnprxy"));
DataStore<StoredCredential> datastore = fileDataStoreFactory.getDataStore(config.getString("versionone.client-id"));
AuthorizationCodeFlow codeFlow = new AuthorizationCodeFlow.Builder(
BearerToken.authorizationHeaderAccessMethod(),
HTTP_TRANSPORT,
JSON_FACTORY,
new GenericUrl(config.getString("versionone.token-uri")),
new ClientParametersAuthentication(config.getString("versionone.client-id"), config.getString("versionone.client-secret")),
config.getString("versionone.client-id"),
config.getString("versionone.auth-uri"))
.setCredentialDataStore(datastore)
.setScopes(SCOPES).build();
return codeFlow;
}
示例15: authorize
import com.google.api.client.util.store.DataStore; //导入依赖的package包/类
/**
* Authorizes the installed application to access user's protected data.
*
* @param scopes list of scopes needed to run youtube upload.
* @param credentialDatastore name of the credential datastore to cache OAuth tokens
*/
public static Credential authorize(List<String> scopes, String credentialDatastore) throws IOException {
// Load client secrets.
Reader clientSecretReader = new InputStreamReader(Auth.class.getResourceAsStream("/client_secrets.json"));
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, clientSecretReader);
// Checks that the defaults have been replaced (Default = "Enter X here").
if (clientSecrets.getDetails().getClientId().startsWith("Enter")
|| clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) {
System.out.println(
"Enter Client ID and Secret from https://code.google.com/apis/console/?api=youtube"
+ "into src/main/resources/client_secrets.json");
System.exit(1);
}
// This creates the credentials datastore at ~/.oauth-credentials/${credentialDatastore}
FileDataStoreFactory fileDataStoreFactory = new FileDataStoreFactory(new File(System.getProperty("user.home") + "/" + CREDENTIALS_DIRECTORY));
DataStore<StoredCredential> datastore = fileDataStoreFactory.getDataStore(credentialDatastore);
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, scopes).setCredentialDataStore(datastore)
.build();
// Build the local server and bind it to port 8080
LocalServerReceiver localReceiver = new LocalServerReceiver.Builder().setPort(8080).build();
// Authorize.
return new AuthorizationCodeInstalledApp(flow, localReceiver).authorize("user");
}