當前位置: 首頁>>代碼示例>>Java>>正文


Java GoogleClientSecrets.setInstalled方法代碼示例

本文整理匯總了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");
}
 
開發者ID:donbeave,項目名稱:grails-google-drive,代碼行數:20,代碼來源:GoogleDrive.java

示例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);
	}
}
 
開發者ID:salrashid123,項目名稱:gcpsamples,代碼行數:31,代碼來源:TestApp.java

示例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");
}
 
開發者ID:GoogleCloudPlatform,項目名稱:bigdata-interop,代碼行數:53,代碼來源:CredentialFactory.java

示例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;
}
 
開發者ID:googleads,項目名稱:googleads-java-lib,代碼行數:11,代碼來源:GoogleClientSecretsBuilder.java


注:本文中的com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets.setInstalled方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。