本文整理汇总了Java中com.google.api.client.googleapis.extensions.java6.auth.oauth2.GooglePromptReceiver类的典型用法代码示例。如果您正苦于以下问题:Java GooglePromptReceiver类的具体用法?Java GooglePromptReceiver怎么用?Java GooglePromptReceiver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GooglePromptReceiver类属于com.google.api.client.googleapis.extensions.java6.auth.oauth2包,在下文中一共展示了GooglePromptReceiver类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: authorize
import com.google.api.client.googleapis.extensions.java6.auth.oauth2.GooglePromptReceiver; //导入依赖的package包/类
/**
* Authorizes the installed application to access user's protected data.
*/
public static Credential authorize() throws IOException {
// Load client secrets.
final byte[] bytes = Files.toByteArray(new File(clientSecretFile));
final GoogleClientSecrets clientSecrets = GoogleClientSecrets
.load(JSON_FACTORY, new InputStreamReader(new ByteArrayInputStream(bytes)));
if (clientSecrets.getDetails().getClientId() == null
|| clientSecrets.getDetails().getClientSecret() == null) {
throw new IllegalStateException("client_secrets not well formed.");
}
// Set up authorization code flow.
// Ask for only the permissions you need. Asking for more permissions will
// reduce the number of users who finish the process for giving you access
// to their accounts. It will also increase the amount of effort you will
// have to spend explaining to users what you are doing with their data.
// Here we are listing all of the available scopes. You should remove scopes
// that you are not actually using.
final Set<String> scopes = new HashSet<String>();
scopes.add(StorageScopes.DEVSTORAGE_FULL_CONTROL);
scopes.add(StorageScopes.DEVSTORAGE_READ_ONLY);
scopes.add(StorageScopes.DEVSTORAGE_READ_WRITE);
final GoogleAuthorizationCodeFlow flow =
new GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY, clientSecrets,
scopes).setDataStoreFactory(dataStoreFactory).build();
// Authorize.
final VerificationCodeReceiver receiver =
AUTH_LOCAL_WEBSERVER ? new LocalServerReceiver() : new GooglePromptReceiver();
return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");
}
示例2: getCredentialFromFileCredentialStoreForInstalledApp
import com.google.api.client.googleapis.extensions.java6.auth.oauth2.GooglePromptReceiver; //导入依赖的package包/类
/**
* Initialized OAuth2 credential for the "installed application" flow; where the credential
* typically represents an actual end user (instead of a service account), and is stored as a
* refresh token in a local FileCredentialStore.
*
* @param clientId OAuth2 client ID identifying the 'installed app'
* @param clientSecret OAuth2 client secret
* @param filePath full path to a ".json" file for storing the credential
* @param scopes list of well-formed scopes desired in the credential
* @param transport The HttpTransport used for authorization
* @return credential with desired scopes, possibly obtained from loading {@code filePath}.
* @throws IOException on IO error
*/
public Credential getCredentialFromFileCredentialStoreForInstalledApp(
String clientId,
String clientSecret,
String filePath,
List<String> scopes,
HttpTransport transport)
throws IOException, GeneralSecurityException {
LOG.debug("getCredentialFromFileCredentialStoreForInstalledApp({}, {}, {}, {})",
clientId, clientSecret, filePath, scopes);
Preconditions.checkArgument(!Strings.isNullOrEmpty(clientId),
"clientId must not be null or empty");
Preconditions.checkArgument(!Strings.isNullOrEmpty(clientSecret),
"clientSecret must not be null or empty");
Preconditions.checkArgument(!Strings.isNullOrEmpty(filePath),
"filePath must not be null or empty");
Preconditions.checkArgument(scopes != null,
"scopes must not be null or empty");
// Initialize client secrets.
GoogleClientSecrets.Details details = new GoogleClientSecrets.Details();
details.setClientId(clientId);
details.setClientSecret(clientSecret);
GoogleClientSecrets clientSecrets = new GoogleClientSecrets();
clientSecrets.setInstalled(details);
// Set up file credential store.
FileCredentialStore credentialStore =
new FileCredentialStore(new File(filePath), JSON_FACTORY);
// Set up authorization code flow.
GoogleAuthorizationCodeFlow flow =
new GoogleAuthorizationCodeFlow.Builder(transport, JSON_FACTORY, clientSecrets, scopes)
.setCredentialStore(credentialStore)
.setRequestInitializer(new CredentialHttpRetryInitializer())
.build();
// Authorize access.
return new AuthorizationCodeInstalledApp(flow, new GooglePromptReceiver()).authorize("user");
}
示例3: authorize
import com.google.api.client.googleapis.extensions.java6.auth.oauth2.GooglePromptReceiver; //导入依赖的package包/类
/** Authorizes the installed application to access user's protected data. */
private static Credential authorize() throws Exception {
// Load client secrets.
GoogleClientSecrets clientSecrets = null;
try {
clientSecrets = GoogleClientSecrets.load(JSON_FACTORY,
new InputStreamReader(StorageSample.class.getResourceAsStream(String.format("/%s",CLIENT_SECRET_FILENAME))));
if (clientSecrets.getDetails().getClientId() == null ||
clientSecrets.getDetails().getClientSecret() == null) {
throw new Exception("client_secrets not well formed.");
}
} catch (Exception e) {
System.out.println("Problem loading client_secrets.json file. Make sure it exists, you are " +
"loading it with the right path, and a client ID and client secret are " +
"defined in it.\n" + e.getMessage());
System.exit(1);
}
// Set up authorization code flow.
// Ask for only the permissions you need. Asking for more permissions will
// reduce the number of users who finish the process for giving you access
// to their accounts. It will also increase the amount of effort you will
// have to spend explaining to users what you are doing with their data.
// Here we are listing all of the available scopes. You should remove scopes
// that you are not actually using.
Set<String> scopes = new HashSet<String>();
scopes.add(StorageScopes.DEVSTORAGE_FULL_CONTROL);
scopes.add(StorageScopes.DEVSTORAGE_READ_ONLY);
scopes.add(StorageScopes.DEVSTORAGE_READ_WRITE);
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
httpTransport, JSON_FACTORY, clientSecrets, scopes)
.setDataStoreFactory(dataStoreFactory)
.build();
// Authorize.
VerificationCodeReceiver receiver =
AUTH_LOCAL_WEBSERVER ? new LocalServerReceiver() : new GooglePromptReceiver();
return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");
}
示例4: authorizeUser
import com.google.api.client.googleapis.extensions.java6.auth.oauth2.GooglePromptReceiver; //导入依赖的package包/类
/**
* Authorizes the installed application to access user's protected data.
*/
private Credential authorizeUser(GoogleClientSecrets clientSecrets) throws Exception
{
// set up file credential store
//CredentialStore credentialStore = new MemoryCredentialStore();
CredentialStore credentialStore = new FileCredentialStore(new java.io.File(CREDENTIAL_FILE), JSON_FACTORY);
// set up authorization code flow
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES).setCredentialStore(credentialStore).build();
// authorize
VerificationCodeReceiver receiver = new GooglePromptReceiver();
return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");
}
示例5: authorizeUser
import com.google.api.client.googleapis.extensions.java6.auth.oauth2.GooglePromptReceiver; //导入依赖的package包/类
/**
* Authorizes the installed application to access user's protected data.
*/
private static Credential authorizeUser(GoogleClientSecrets clientSecrets) throws Exception
{
// set up file credential store
//CredentialStore credentialStore = new MemoryCredentialStore();
CredentialStore credentialStore = new FileCredentialStore(new java.io.File(CREDENTIAL_FILE), JSON_FACTORY);
// set up authorization code flow
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES).setCredentialStore(credentialStore).build();
// authorize
VerificationCodeReceiver receiver = new GooglePromptReceiver();
return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");
}