本文整理汇总了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);
}
示例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);
}
示例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();
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}