本文整理汇总了Java中com.google.api.client.util.store.FileDataStoreFactory.getDataStore方法的典型用法代码示例。如果您正苦于以下问题:Java FileDataStoreFactory.getDataStore方法的具体用法?Java FileDataStoreFactory.getDataStore怎么用?Java FileDataStoreFactory.getDataStore使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.api.client.util.store.FileDataStoreFactory
的用法示例。
在下文中一共展示了FileDataStoreFactory.getDataStore方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: authorize
import com.google.api.client.util.store.FileDataStoreFactory; //导入方法依赖的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: authorize
import com.google.api.client.util.store.FileDataStoreFactory; //导入方法依赖的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");
}
示例3: authorize
import com.google.api.client.util.store.FileDataStoreFactory; //导入方法依赖的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());
}
示例4: authorize
import com.google.api.client.util.store.FileDataStoreFactory; //导入方法依赖的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");
}
示例5: authorize
import com.google.api.client.util.store.FileDataStoreFactory; //导入方法依赖的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");
}
示例6: storeOAuth2TokenData
import com.google.api.client.util.store.FileDataStoreFactory; //导入方法依赖的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;
}
示例7: authorize
import com.google.api.client.util.store.FileDataStoreFactory; //导入方法依赖的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");
}
示例8: getStoredCredentialDataStore
import com.google.api.client.util.store.FileDataStoreFactory; //导入方法依赖的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");
}
示例9: initializeAuthorizationFlow
import com.google.api.client.util.store.FileDataStoreFactory; //导入方法依赖的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;
}
示例10: authorize
import com.google.api.client.util.store.FileDataStoreFactory; //导入方法依赖的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");
}
示例11: deleteStoredOAuth2TokenData
import com.google.api.client.util.store.FileDataStoreFactory; //导入方法依赖的package包/类
/**
* Deletes the TokenResponse that is associated with the given storageId from the file data store.
*
* @param storageId The storageId associated with the stored TokenResponse.
*/
public void deleteStoredOAuth2TokenData(String storageId) {
try {
File oauth2StorageFolder = new File(this.context.getFilesDir(),"oauth2StorageFolder");
oauth2StorageFolder.mkdirs();
FileDataStoreFactory fileDataStoreFactory = new FileDataStoreFactory(oauth2StorageFolder);
DataStore<StoredCredential> storedCredentialDataStore = fileDataStoreFactory.getDataStore(storageId);
storedCredentialDataStore.delete(storageId);
} catch ( Exception exception ) {
logInfo("Exception deleting OAuth2TokenData :" + exception.getLocalizedMessage());
}
}
示例12: addCredentialToDataStore
import com.google.api.client.util.store.FileDataStoreFactory; //导入方法依赖的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);
}