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


Java DataStoreFactory类代码示例

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


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

示例1: authorize

import com.google.api.client.util.store.DataStoreFactory; //导入依赖的package包/类
private static void authorize(DataStoreFactory storeFactory, String userId) throws Exception {
  // Depending on your application, there may be more appropriate ways of
  // performing the authorization flow (such as on a servlet), see
  // https://developers.google.com/api-client-library/java/google-api-java-client/oauth2#authorization_code_flow
  // for more information.
  GoogleAuthorizationCodeFlow authorizationFlow = new GoogleAuthorizationCodeFlow.Builder(
      new NetHttpTransport(),
      new JacksonFactory(),
      CLIENT_ID,
      CLIENT_SECRET,
      Arrays.asList(SCOPE))
      .setDataStoreFactory(storeFactory)
      // Set the access type to offline so that the token can be refreshed.
      // By default, the library will automatically refresh tokens when it
      // can, but this can be turned off by setting
      // api.dfp.refreshOAuth2Token=false in your ads.properties file.
      .setAccessType("offline").build();

  String authorizeUrl =
      authorizationFlow.newAuthorizationUrl().setRedirectUri(CALLBACK_URL).build();
  System.out.printf("Paste this url in your browser:%n%s%n", authorizeUrl);

  // Wait for the authorization code.
  System.out.println("Type the code you received here: ");
  @SuppressWarnings("DefaultCharset") // Reading from stdin, so default charset is appropriate.
  String authorizationCode = new BufferedReader(new InputStreamReader(System.in)).readLine();

  // Authorize the OAuth2 token.
  GoogleAuthorizationCodeTokenRequest tokenRequest =
      authorizationFlow.newTokenRequest(authorizationCode);
  tokenRequest.setRedirectUri(CALLBACK_URL);
  GoogleTokenResponse tokenResponse = tokenRequest.execute();

  // Store the credential for the user.
  authorizationFlow.createAndStoreCredential(tokenResponse, userId);
}
 
开发者ID:googleads,项目名称:googleads-java-lib,代码行数:37,代码来源:AdvancedCreateCredentialFromScratch.java

示例2: configure

import com.google.api.client.util.store.DataStoreFactory; //导入依赖的package包/类
@Override
	public void configure(Binder binder) {

//		binder.bind(HttpTransport.class).toInstance(new UrlFetchTransport());
		binder.bind(HttpTransport.class).toInstance(new NetHttpTransport());

		/*
		 * TODO HH?
		 */
		binder.bind(DateFormat.class).toInstance(
				new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SSS'Z'"));

		binder.bind(JsonFactory.class).toInstance(
				JacksonFactory.getDefaultInstance());

		/*
		 * Global instance of the {@link DataStoreFactory}. The best practice is
		 * to make it a single globally shared instance across your application.
		 */
		binder.bind(DataStoreFactory.class).toInstance(
				AppEngineDataStoreFactory.getDefaultInstance());
		binder.bind(AppEngineDataStoreFactory.class).in(Singleton.class);
	}
 
开发者ID:HotswapProjects,项目名称:HotswapAgentExamples,代码行数:24,代码来源:DevelopersSharedModule.java

示例3: createDfpSession

import com.google.api.client.util.store.DataStoreFactory; //导入依赖的package包/类
private static DfpSession createDfpSession(DataStoreFactory storeFactory, String userId)
    throws IOException, ValidationException, ConfigurationLoadException {

  // Create a GoogleCredential with minimal information.
  GoogleAuthorizationCodeFlow authorizationFlow = new GoogleAuthorizationCodeFlow.Builder(
      new NetHttpTransport(),
      new JacksonFactory(),
      CLIENT_ID,
      CLIENT_SECRET,
      Arrays.asList(SCOPE))
      .setDataStoreFactory(storeFactory).build();

  // Load the credential.
  Credential credential = authorizationFlow.loadCredential(userId);

  // Construct a DfpSession.
  return new DfpSession.Builder()
      .fromFile()
      .withOAuth2Credential(credential)
      .build();
}
 
开发者ID:googleads,项目名称:googleads-java-lib,代码行数:22,代码来源:AdvancedCreateCredentialFromScratch.java

示例4: main

import com.google.api.client.util.store.DataStoreFactory; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
  if (CLIENT_ID.equals("INSERT_CLIENT_ID_HERE")
      || CLIENT_SECRET.equals("INSERT_CLIENT_SECRET_HERE")) {
    throw new IllegalArgumentException("Please input your client IDs or secret. "
        + "See https://console.developers.google.com/project");
  }

  // It is highly recommended that you use a credential store in your
  // application to store a per-user Credential.
  // See: https://developers.google.com/api-client-library/java/google-api-java-client/oauth2#data_store
  DataStoreFactory storeFactory = new MemoryDataStoreFactory();

  // Authorize and store your credential.
  authorize(storeFactory, USER_ID);

  // Create a DfpSession from the credential store. You will typically do this
  // in a servlet interceptor for a web application or per separate thread
  // of your offline application.
  DfpSession dfpSession = createDfpSession(storeFactory, USER_ID);

  DfpServices dfpServices = new DfpServices();

  runExample(dfpServices, dfpSession);
}
 
开发者ID:googleads,项目名称:googleads-java-lib,代码行数:25,代码来源:AdvancedCreateCredentialFromScratch.java

示例5: initialise

import com.google.api.client.util.store.DataStoreFactory; //导入依赖的package包/类
@Override
public void initialise(UpdatableInjectionContext injectionContext) {
    super.initialise(injectionContext);

    // for gmail API as the setup stores the creds established at setup time in DS
    injectionContext.inject(AppEngineDataStoreFactory.getDefaultInstance()).as(DataStoreFactory.class);
    injectionContext.inject(UrlFetchTransport.getDefaultInstance()).as(HttpTransport.class);

    Class<? extends Mailer> mailerClass = Environment.is(Environment.DEV) ? LoggingMailer.class : GmailMailer.class;
    injectionContext.inject(mailerClass).as(Mailer.class);
}
 
开发者ID:3wks,项目名称:generator-thundr-gae-react,代码行数:12,代码来源:UserManagerModule.java

示例6: FitbitUserCredentialManager

import com.google.api.client.util.store.DataStoreFactory; //导入依赖的package包/类
public FitbitUserCredentialManager(
        DataStoreFactory dataStoreFactory,
        FitbitClientCredentials credentials) throws IOException {

    this.dataStoreFactory = dataStoreFactory;
    this.credentials = credentials;

    this.basicAuthentication =
            new BasicAuthentication(credentials.getId(), credentials.getSecret());

    this.flow = new AuthorizationCodeFlow.Builder(
            BearerToken.authorizationHeaderAccessMethod(),
            transport,
            gsonFactory,
            tokenEndPoint,
            this.basicAuthentication,
            this.credentials.getId(),
            FitbitApiConfig.AUTHORIZE_URL)
            .setScopes(Arrays.asList("activity"))
            .setDataStoreFactory(dataStoreFactory)
            .build();

    this.credentialBuilder = new Credential.Builder(BearerToken.authorizationHeaderAccessMethod())
            .setClientAuthentication(this.basicAuthentication)
            .setJsonFactory(gsonFactory)
            .setTransport(transport)
            .setTokenServerUrl(tokenEndPoint);
}
 
开发者ID:TickleThePanda,项目名称:health-vis,代码行数:29,代码来源:FitbitUserCredentialManager.java

示例7: authorize

import com.google.api.client.util.store.DataStoreFactory; //导入依赖的package包/类
private static void authorize(DataStoreFactory storeFactory, String userId) throws Exception {
  // Depending on your application, there may be more appropriate ways of
  // performing the authorization flow (such as on a servlet), see
  // https://developers.google.com/api-client-library/java/google-api-java-client/oauth2#authorization_code_flow
  // for more information.
  GoogleAuthorizationCodeFlow authorizationFlow = new GoogleAuthorizationCodeFlow.Builder(
      new NetHttpTransport(),
      new JacksonFactory(),
      CLIENT_ID,
      CLIENT_SECRET,
      Arrays.asList(SCOPE))
      .setDataStoreFactory(storeFactory)
      // Set the access type to offline so that the token can be refreshed.
      // By default, the library will automatically refresh tokens when it
      // can, but this can be turned off by setting
      // api.adwords.refreshOAuth2Token=false in your ads.properties file.
      .setAccessType("offline").build();

  String authorizeUrl =
      authorizationFlow.newAuthorizationUrl().setRedirectUri(CALLBACK_URL).build();
  System.out.printf("Paste this url in your browser:%n%s%n", authorizeUrl);

  // Wait for the authorization code.
  System.out.println("Type the code you received here: ");
  @SuppressWarnings("DefaultCharset") // Reading from stdin, so default charset is appropriate.
  String authorizationCode = new BufferedReader(new InputStreamReader(System.in)).readLine();

  // Authorize the OAuth2 token.
  GoogleAuthorizationCodeTokenRequest tokenRequest =
      authorizationFlow.newTokenRequest(authorizationCode);
  tokenRequest.setRedirectUri(CALLBACK_URL);
  GoogleTokenResponse tokenResponse = tokenRequest.execute();

  // Store the credential for the user.
  authorizationFlow.createAndStoreCredential(tokenResponse, userId);
}
 
开发者ID:googleads,项目名称:googleads-java-lib,代码行数:37,代码来源:AdvancedCreateCredentialFromScratch.java

示例8: main

import com.google.api.client.util.store.DataStoreFactory; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
  if (CLIENT_ID.equals("INSERT_CLIENT_ID_HERE")
      || CLIENT_SECRET.equals("INSERT_CLIENT_SECRET_HERE")) {
    throw new IllegalArgumentException("Please input your client IDs or secret. "
        + "See https://console.developers.google.com/project");
  }

  // It is highly recommended that you use a credential store in your
  // application to store a per-user Credential.
  // See: https://developers.google.com/api-client-library/java/google-api-java-client/oauth2#data_store
  DataStoreFactory storeFactory = new MemoryDataStoreFactory();

  // Authorize and store your credential.
  authorize(storeFactory, USER_ID);

  // Create a AdWordsSession from the credential store. You will typically do this
  // in a servlet interceptor for a web application or per separate thread
  // of your offline application.
  AdWordsSession adWordsSession = createAdWordsSession(USER_ID);

  AdWordsServicesInterface adWordsServices = AdWordsServices.getInstance();

  // Location to download report to.
  String reportFile = System.getProperty("user.home") + File.separatorChar + "report.csv";

  runExample(adWordsServices, adWordsSession, reportFile);
}
 
开发者ID:googleads,项目名称:googleads-java-lib,代码行数:28,代码来源:AdvancedCreateCredentialFromScratch.java

示例9: getDataStoreFactory

import com.google.api.client.util.store.DataStoreFactory; //导入依赖的package包/类
/** Gets the datastore factory used in these samples. */
public static DataStoreFactory getDataStoreFactory() {
  return dataStoreFactory;
}
 
开发者ID:googlesamples,项目名称:calendar-sync,代码行数:5,代码来源:Utils.java

示例10: CustomDataStore

import com.google.api.client.util.store.DataStoreFactory; //导入依赖的package包/类
/**
 * @param dataStoreFactory data store factory
 * @param id data store ID
 */
protected CustomDataStore(DataStoreFactory dataStoreFactory, String id) {
  super(dataStoreFactory, id);
}
 
开发者ID:curiosag,项目名称:ftc,代码行数:8,代码来源:CustomDataStore.java


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