本文整理汇总了Java中com.google.api.client.util.store.DataStore类的典型用法代码示例。如果您正苦于以下问题:Java DataStore类的具体用法?Java DataStore怎么用?Java DataStore使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DataStore类属于com.google.api.client.util.store包,在下文中一共展示了DataStore类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: authorize
import com.google.api.client.util.store.DataStore; //导入依赖的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: loadCredential
import com.google.api.client.util.store.DataStore; //导入依赖的package包/类
private static Credential loadCredential(String userId, DataStore<StoredCredential> credentialDataStore)
throws IOException {
Credential credential = newCredential(userId, credentialDataStore);
if (credentialDataStore != null) {
StoredCredential stored = credentialDataStore.get(userId);
if (stored == null) {
return null;
}
credential.setAccessToken(stored.getAccessToken());
credential.setRefreshToken(stored.getRefreshToken());
credential.setExpirationTimeMilliseconds(stored.getExpirationTimeMilliseconds());
if (logger.isDebugEnabled()) {
logger.debug("Loaded credential");
logger.debug("device access token: {}", stored.getAccessToken());
logger.debug("device refresh_token: {}", stored.getRefreshToken());
logger.debug("device expires_in: {}", stored.getExpirationTimeMilliseconds());
}
}
return credential;
}
开发者ID:openhab,项目名称:openhab1-addons,代码行数:21,代码来源:GCalGoogleOAuth.java
示例3: authorize
import com.google.api.client.util.store.DataStore; //导入依赖的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
示例4: authorize
import com.google.api.client.util.store.DataStore; //导入依赖的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
示例5: authorize
import com.google.api.client.util.store.DataStore; //导入依赖的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
示例6: authorize
import com.google.api.client.util.store.DataStore; //导入依赖的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
示例7: storeOAuth2TokenData
import com.google.api.client.util.store.DataStore; //导入依赖的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
示例8: delete
import com.google.api.client.util.store.DataStore; //导入依赖的package包/类
public DataStore<V> delete( String key ) throws IOException {
if ( key == null ) {
return this;
} else {
this.lock.lock();
try {
this.keyValueMap.remove( key );
this.save();
} finally {
this.lock.unlock();
}
return this;
}
}
开发者ID:pentaho,项目名称:pentaho-kettle,代码行数:17,代码来源:CustomDataStoreFactory.java
示例9: set
import com.google.api.client.util.store.DataStore; //导入依赖的package包/类
public final DataStore<V> set(String key, V value) throws IOException {
Preconditions.checkNotNull(key);
Preconditions.checkNotNull(value);
lock.lock();
try {
keyValueMap.put(key, IOUtils.serialize(value));
save();
} finally {
lock.unlock();
}
return this;
}
开发者ID:curiosag,项目名称:ftc,代码行数:13,代码来源:CustomDataStore.java
示例10: delete
import com.google.api.client.util.store.DataStore; //导入依赖的package包/类
public DataStore<V> delete(String key) throws IOException {
if (key == null) {
return this;
}
lock.lock();
try {
keyValueMap.remove(key);
save();
} finally {
lock.unlock();
}
return this;
}
开发者ID:curiosag,项目名称:ftc,代码行数:14,代码来源:CustomDataStore.java
示例11: clear
import com.google.api.client.util.store.DataStore; //导入依赖的package包/类
public final DataStore<V> clear() throws IOException {
lock.lock();
try {
keyValueMap.clear();
save();
} finally {
lock.unlock();
}
return this;
}
开发者ID:curiosag,项目名称:ftc,代码行数:11,代码来源:CustomDataStore.java
示例12: authorize
import com.google.api.client.util.store.DataStore; //导入依赖的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
示例13: getStoredCredentialDataStore
import com.google.api.client.util.store.DataStore; //导入依赖的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
示例14: initializeAuthorizationFlow
import com.google.api.client.util.store.DataStore; //导入依赖的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
示例15: authorize
import com.google.api.client.util.store.DataStore; //导入依赖的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
示例16: set
import com.google.api.client.util.store.DataStore; //导入依赖的package包/类
public DataStore<StoredCredential> set(String key, StoredCredential value) throws IOException {
if (key != UNUSED_ID) {
throw new IOException("Unexpected real user ID");
}
token = Token.fromStoredCredential(value);
writeToken();
return this;
}
开发者ID:googleads,项目名称:googleads-shopping-samples,代码行数:9,代码来源:ConfigDataStoreFactory.java
示例17: getInMemoryDatastore
import com.google.api.client.util.store.DataStore; //导入依赖的package包/类
public DataStore<StoredCredential> getInMemoryDatastore() {
if (inmemoryDatastore == null) {
try {
inmemoryDatastore = MemoryDataStoreFactory.getDefaultInstance().getDataStore("ListableMemoryCredentialStore");
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
}
return inmemoryDatastore;
}
开发者ID:eteration,项目名称:glassmaker,代码行数:11,代码来源:OAuth2Util.java
示例18: newCredential
import com.google.api.client.util.store.DataStore; //导入依赖的package包/类
private static Credential newCredential(String userId, DataStore<StoredCredential> credentialDataStore) {
Credential.Builder builder = new Credential.Builder(BearerToken.authorizationHeaderAccessMethod())
.setTransport(HTTP_TRANSPORT).setJsonFactory(JSON_FACTORY)
.setTokenServerEncodedUrl("https://accounts.google.com/o/oauth2/token")
.setClientAuthentication(new ClientParametersAuthentication(client_id, client_secret))
.setRequestInitializer(null).setClock(Clock.SYSTEM);
builder.addRefreshListener(new DataStoreCredentialRefreshListener(userId, credentialDataStore));
return builder.build();
}
开发者ID:openhab,项目名称:openhab1-addons,代码行数:13,代码来源:GCalGoogleOAuth.java
示例19: deleteStoredOAuth2TokenData
import com.google.api.client.util.store.DataStore; //导入依赖的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
示例20: clear
import com.google.api.client.util.store.DataStore; //导入依赖的package包/类
public final DataStore<V> clear() throws IOException {
this.lock.lock();
try {
this.keyValueMap.clear();
this.save();
} finally {
this.lock.unlock();
}
return this;
}
开发者ID:pentaho,项目名称:pentaho-kettle,代码行数:13,代码来源:CustomDataStoreFactory.java
注:本文中的com.google.api.client.util.store.DataStore类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论