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


Java FileDataStoreFactory类代码示例

本文整理汇总了Java中com.google.api.client.util.store.FileDataStoreFactory的典型用法代码示例。如果您正苦于以下问题:Java FileDataStoreFactory类的具体用法?Java FileDataStoreFactory怎么用?Java FileDataStoreFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FileDataStoreFactory类属于com.google.api.client.util.store包,在下文中一共展示了FileDataStoreFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: doLogin

import com.google.api.client.util.store.FileDataStoreFactory; //导入依赖的package包/类
public static void doLogin(String user){
    try {
        httpTransport = GoogleNetHttpTransport.newTrustedTransport();
        dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR);
        Credential credential = authorize(user);
        oauth2 = new Oauth2.Builder(httpTransport, JSON_FACTORY, credential).setApplicationName(APPLICATION_NAME).build();
        String picture = oauth2.userinfo().get().execute().getPicture();
        //name = oauth2.userinfo().get().execute().getName();
        downloadProfileImage(picture,user.toLowerCase());
        
  } catch (IOException e) {
    System.err.println(e.getMessage());
  } catch (Exception t) {

  }
}
 
开发者ID:Obsidiam,项目名称:amelia,代码行数:17,代码来源:AuthorizeGoogleUser.java

示例3: GoogleConnector

import com.google.api.client.util.store.FileDataStoreFactory; //导入依赖的package包/类
/**
 * Instances the google connector configuring all required resources.
 */
private GoogleConnector() throws IOException, GeneralSecurityException {
    super();
    // 1. JSON library
    jsonFactory = JacksonFactory.getDefaultInstance();

    // 2. Configure HTTP transport
    httpTransport = GoogleNetHttpTransport.newTrustedTransport();

    // 3. Load the credentials
    secrets = GoogleClientSecrets.load(jsonFactory, new InputStreamReader(GoogleConnector.class.getResourceAsStream("client-secrets.json")));

    // 4. Configure the authentication flow
    dataStoreFactory = new FileDataStoreFactory(CREDENTIALS_DIRECTORY);

    // 5. Create flow
    imp_buildAuthorizationFlow();
}
 
开发者ID:dlemmermann,项目名称:CalendarFX,代码行数:21,代码来源:GoogleConnector.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(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

示例5: init

import com.google.api.client.util.store.FileDataStoreFactory; //导入依赖的package包/类
public GoogleCalendarSync init() throws Exception {
    // initialize the transport
    httpTransport = GoogleNetHttpTransport.newTrustedTransport();

    // initialize the data store factory
    dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR);

    // authorization
    final Credential credential = authorize();

    // set up global Calendar instance
    client = new com.google.api.services.calendar.Calendar.Builder(httpTransport, JSON_FACTORY, credential)
            .setApplicationName(APPLICATION_NAME).build();

    return this;
}
 
开发者ID:DrBookings,项目名称:drbookings,代码行数:17,代码来源:GoogleCalendarSync.java

示例6: authorize

import com.google.api.client.util.store.FileDataStoreFactory; //导入依赖的package包/类
private Sheets authorize() {
  try {
    InputStream in = new FileInputStream(new File(System.getenv("GOOGLE_OATH2_CREDENTIALS")));
    JsonFactory factory = new JacksonFactory();
    GoogleClientSecrets clientSecrets =
        GoogleClientSecrets.load(factory, new InputStreamReader(in, Charset.defaultCharset()));
    HttpTransport transport = GoogleNetHttpTransport.newTrustedTransport();
    FileDataStoreFactory dataStoreFactory =
        new FileDataStoreFactory(new File(dataStoreDirectory));
    List<String> scopes = Collections.singletonList(SheetsScopes.SPREADSHEETS);
    GoogleAuthorizationCodeFlow flow =
        new GoogleAuthorizationCodeFlow.Builder(transport, factory, clientSecrets, scopes)
            .setAccessType("offline")
            .setDataStoreFactory(dataStoreFactory)
            .build();
    Credential credential =
        new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
    return new Sheets.Builder(transport, factory, credential)
        .setApplicationName(APPLICATION_NAME)
        .build();
  } catch (Exception e) {
    return null;
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:pubsub,代码行数:25,代码来源:SheetsService.java

示例7: authorize

import com.google.api.client.util.store.FileDataStoreFactory; //导入依赖的package包/类
private Credential authorize(final IProgressMonitor monitor) throws IOException {
	try {
		monitor.beginTask("Authorizes the application to access user's protected data on Google Drive", 100);
		// load client secrets
		// In this context, the client secret is obviously not treated as a
		// secret.
		GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY,
				new InputStreamReader(GDriveConnectionManager.class.getResourceAsStream("client_secrets.json")));
		// set up authorization code flow
		FileDataStoreFactory dataStoreFactory = new FileDataStoreFactory(dataStoreDir);
		GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY,
				clientSecrets, Collections.singleton(DriveScopes.DRIVE)).setDataStoreFactory(dataStoreFactory)
						.build();
		// authorize
		LocalServerReceiver localServerReceiver = new CancellableLocalServerReceiver(monitor);
		AuthorizationCodeInstalledApp authorizationCodeInstalledApp = authorizationCodeInstalledAppProvider
				.get(flow, localServerReceiver, monitor);
		return authorizationCodeInstalledApp.authorize("user");
	} finally {
		monitor.done();
	}
}
 
开发者ID:cchabanois,项目名称:mesfavoris,代码行数:23,代码来源:GDriveConnectionManager.java

示例8: getGmailService

import com.google.api.client.util.store.FileDataStoreFactory; //导入依赖的package包/类
private static Gmail getGmailService(String basedir, String appName) throws Exception {

        // 機密情報ファイルのパス
        File DATA_STORE_DIR = new java.io.File(basedir, "gmail-secrets");
        File SECRET_JSON = new java.io.File(DATA_STORE_DIR, "client_secret.json");

        // 準備
        FileDataStoreFactory DATA_STORE_FACTORY = new FileDataStoreFactory(DATA_STORE_DIR);
        JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
        HttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();

        // 送信のみ
        List<String> SCOPES = Arrays.asList(GmailScopes.GMAIL_SEND);

        // Credential取得
        try (InputStream in = FileUtils.openInputStream(SECRET_JSON)) {
            GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));
            GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY,
                    clientSecrets, SCOPES).setDataStoreFactory(DATA_STORE_FACTORY).setAccessType("offline").build();
            Credential credential = new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");

            // Gmailインスタンス生成
            return new Gmail.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential).setApplicationName(appName).build();
        }
    }
 
开发者ID:af-not-found,项目名称:blog-java2,代码行数:26,代码来源:SmtpManager.java

示例9: 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

示例10: 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

示例11: createOAuth2Credentials

import com.google.api.client.util.store.FileDataStoreFactory; //导入依赖的package包/类
/**
 * Creates an {@link OAuth2Credentials} object that can be used by any of the servlets.
 */
public static OAuth2Credentials createOAuth2Credentials(SessionConfiguration sessionConfiguration) throws Exception {




    // Store the users OAuth2 credentials in their home directory.
    File credentialDirectory =
            new File(System.getProperty("user.home") + File.separator + ".uber_credentials");
    credentialDirectory.setReadable(true, true);
    credentialDirectory.setWritable(true, true);
    // If you'd like to store them in memory or in a DB, any DataStoreFactory can be used.
    AbstractDataStoreFactory dataStoreFactory = new FileDataStoreFactory(credentialDirectory);

    // Build an OAuth2Credentials object with your secrets.
    return new OAuth2Credentials.Builder()
            .setCredentialDataStoreFactory(dataStoreFactory)
            .setRedirectUri(sessionConfiguration.getRedirectUri())
            .setClientSecrets(sessionConfiguration.getClientId(), sessionConfiguration.getClientSecret())
            .build();
}
 
开发者ID:uber,项目名称:rides-java-sdk,代码行数:24,代码来源:GetUserProfile.java

示例12: getCredential

import com.google.api.client.util.store.FileDataStoreFactory; //导入依赖的package包/类
private Credential getCredential(NetHttpTransport httpTransport) throws IOException, GeneralSecurityException {
    GoogleDriveConnectionProperties conn = getConnectionProperties();
    /* get rid of warning on windows until fixed... https://github.com/google/google-http-java-client/issues/315 */
    final java.util.logging.Logger dsLogger = java.util.logging.Logger.getLogger(FileDataStoreFactory.class.getName());
    dsLogger.setLevel(java.util.logging.Level.SEVERE);
    File dataStore;
    switch (conn.oAuthMethod.getValue()) {
    case AccessToken:
        return GoogleDriveCredentialWithAccessToken.builder().accessToken(conn.accessToken.getValue()).build();
    case InstalledApplicationWithIdAndSecret:
        dataStore = new File(conn.datastorePath.getValue());
        return GoogleDriveCredentialWithInstalledApplication.builderWithIdAndSecret(httpTransport, dataStore)
                .clientId(conn.clientId.getValue()).clientSecret(conn.clientSecret.getValue()).build();
    case InstalledApplicationWithJSON:
        dataStore = new File(conn.datastorePath.getValue());
        return GoogleDriveCredentialWithInstalledApplication.builderWithJSON(httpTransport, dataStore)
                .clientSecretFile(new File(conn.clientSecretFile.getValue())).build();
    case ServiceAccount:
        return GoogleDriveCredentialWithServiceAccount.builder()
                .serviceAccountJSONFile(new File(conn.serviceAccountFile.getValue())).build();
    }
    throw new IllegalArgumentException(messages.getMessage("error.credential.oaut.method"));
}
 
开发者ID:Talend,项目名称:components,代码行数:24,代码来源:GoogleDriveRuntime.java

示例13: authorizeWithInstalledApplication

import com.google.api.client.util.store.FileDataStoreFactory; //导入依赖的package包/类
/**
 * Authorizes the installed application to access user's protected data.
 *
 * @throws IOException
 * @throws GeneralSecurityException
 */
private static Credential authorizeWithInstalledApplication() throws IOException {
    log.info("Authorizing using installed application");

    // load client secrets
    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(
            JSON_FACTORY,
            new InputStreamReader(
                    AndroidPublisherHelper.class
                            .getResourceAsStream(RESOURCES_CLIENT_SECRETS_JSON)));
    // Ensure file has been filled out.
    checkClientSecretsFile(clientSecrets);

    dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR);

    // set up authorization code flow
    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow
            .Builder(HTTP_TRANSPORT,
            JSON_FACTORY, clientSecrets,
            Collections.singleton(AndroidPublisherScopes.ANDROIDPUBLISHER))
            .setDataStoreFactory(dataStoreFactory).build();
    // authorize
    return new AuthorizationCodeInstalledApp(
            flow, new LocalServerReceiver()).authorize(INST_APP_USER_ID);
}
 
开发者ID:wisobi,项目名称:leanbean,代码行数:31,代码来源:AndroidPublisherHelper.java

示例14: 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

示例15: authorizeWithInstalledApplication

import com.google.api.client.util.store.FileDataStoreFactory; //导入依赖的package包/类
/**
 * Authorizes the installed application to access user's protected data.
 *
 * @throws IOException
 * @throws GeneralSecurityException
 */
private static Credential authorizeWithInstalledApplication() throws IOException {
    log.info("Authorizing using installed application");

    // load client secrets
    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(
            JSON_FACTORY,
            new InputStreamReader(
                    AndroidPublisherHelper.class
                            .getResourceAsStream(RESOURCES_CLIENT_SECRETS_JSON)));
    // Ensure file has been filled out.
    checkClientSecretsFile(clientSecrets);

    dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR);

    // set up authorization code flow
    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow
            .Builder(HTTP_TRANSPORT,
                    JSON_FACTORY, clientSecrets,
                    Collections.singleton(AndroidPublisherScopes.ANDROIDPUBLISHER))
                    .setDataStoreFactory(dataStoreFactory).build();
    // authorize
    return new AuthorizationCodeInstalledApp(
            flow, new LocalServerReceiver()).authorize(INST_APP_USER_ID);
}
 
开发者ID:rocel,项目名称:playstorepublisher,代码行数:31,代码来源:AndroidPublisherHelper.java


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