当前位置: 首页>>代码示例>>Java>>正文


Java FileDataStoreFactory.getDataStore方法代码示例

本文整理汇总了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");
}
 
开发者ID:youtube,项目名称:youtube-chat-for-minecraft,代码行数:28,代码来源:Auth.java

示例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");
    }
 
开发者ID:prakamya-mishra,项目名称:Shield,代码行数:25,代码来源:Auth.java

示例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());
}
 
开发者ID:LehmRob,项目名称:FeedMeYoutube,代码行数:38,代码来源:Auth.java

示例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");
}
 
开发者ID:MCUpdater,项目名称:RavenBot,代码行数:18,代码来源:YTAuth.java

示例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");
}
 
开发者ID:donbeave,项目名称:grails-google-drive,代码行数:20,代码来源:GoogleDrive.java

示例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;
}
 
开发者ID:apigee,项目名称:apigee-android-sdk,代码行数:26,代码来源:ApigeeDataClient.java

示例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");
}
 
开发者ID:ashwinswaroop,项目名称:YouTubeBot,代码行数:36,代码来源:Authorizer.java

示例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");
}
 
开发者ID:google,项目名称:mail-importer,代码行数:9,代码来源:Authorizer.java

示例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;
}
 
开发者ID:bwinparty,项目名称:knbnprxy,代码行数:16,代码来源:V1Client.java

示例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");
}
 
开发者ID:HearthStats,项目名称:HearthStats.net-Uploader,代码行数:36,代码来源:Auth.java

示例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());
    }
}
 
开发者ID:apigee,项目名称:apigee-android-sdk,代码行数:17,代码来源:ApigeeDataClient.java

示例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);		
}
 
开发者ID:cchabanois,项目名称:mesfavoris,代码行数:6,代码来源:GDriveConnectionManagerTest.java


注:本文中的com.google.api.client.util.store.FileDataStoreFactory.getDataStore方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。