本文整理汇总了Java中com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets.setInstalled方法的典型用法代码示例。如果您正苦于以下问题:Java GoogleClientSecrets.setInstalled方法的具体用法?Java GoogleClientSecrets.setInstalled怎么用?Java GoogleClientSecrets.setInstalled使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets
的用法示例。
在下文中一共展示了GoogleClientSecrets.setInstalled方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: authorize
import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets; //导入方法依赖的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");
}
示例2: TestApp
import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets; //导入方法依赖的package包/类
public TestApp() {
try
{
HttpTransport httpTransport = new NetHttpTransport();
JacksonFactory jsonFactory = new JacksonFactory();
GoogleClientSecrets clientSecrets = new GoogleClientSecrets();
GoogleClientSecrets.Details det = new GoogleClientSecrets.Details();
det.setClientId("YOUR_CLIENT_ID");
det.setClientSecret("YOUR_CLIENT_SECRET");
det.setRedirectUris(Arrays.asList("urn:ietf:wg:oauth:2.0:oob"));
clientSecrets.setInstalled(det);
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
httpTransport, jsonFactory, clientSecrets,
Arrays.asList(Oauth2Scopes.USERINFO_EMAIL)).build();
Credential credential = new AuthorizationCodeInstalledApp(flow,
new LocalServerReceiver()).authorize("user");
Oauth2 service = new Oauth2.Builder(httpTransport, jsonFactory, credential)
.setApplicationName("oauth client").build();
Userinfoplus ui = service.userinfo().get().execute();
System.out.println(ui.getEmail());
}
catch (Exception ex) {
System.out.println("Error: " + ex);
}
}
示例3: getCredentialFromFileCredentialStoreForInstalledApp
import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets; //导入方法依赖的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");
}
示例4: build
import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets; //导入方法依赖的package包/类
@Override
public GoogleClientSecrets build() throws ValidationException {
validate();
Details details = new Details();
details.setClientId(clientId);
details.setClientSecret(clientSecret);
GoogleClientSecrets googleClientSecrets = new GoogleClientSecrets();
googleClientSecrets.setInstalled(details);
return googleClientSecrets;
}