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


Java GoogleNetHttpTransport.newTrustedTransport方法代碼示例

本文整理匯總了Java中com.google.api.client.googleapis.javanet.GoogleNetHttpTransport.newTrustedTransport方法的典型用法代碼示例。如果您正苦於以下問題:Java GoogleNetHttpTransport.newTrustedTransport方法的具體用法?Java GoogleNetHttpTransport.newTrustedTransport怎麽用?Java GoogleNetHttpTransport.newTrustedTransport使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.api.client.googleapis.javanet.GoogleNetHttpTransport的用法示例。


在下文中一共展示了GoogleNetHttpTransport.newTrustedTransport方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: performRequest

import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; //導入方法依賴的package包/類
private static void performRequest(String accessToken, String refreshToken, String apiKey, String apiSecret) throws GeneralSecurityException, IOException, MessagingException {
	HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
	JsonFactory jsonFactory = new JacksonFactory();
	final Credential credential = convertToGoogleCredential(accessToken, refreshToken, apiSecret, apiKey);
	Builder builder = new Gmail.Builder(httpTransport, jsonFactory, credential);
	builder.setApplicationName("OAuth API Sample");
	Gmail gmail = builder.build();
	MimeMessage content = createEmail("[email protected]", "[email protected]", "Test Email", "It works");
	Message message = createMessageWithEmail(content);
	gmail.users().messages().send("[email protected]", message).execute();
}
 
開發者ID:tburne,項目名稱:blog-examples,代碼行數:12,代碼來源:ClientRequestAPI.java

示例2: doLogin

import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; //導入方法依賴的package包/類
public static void doLogin(String user){
    try {
        httpTransport = GoogleNetHttpTransport.newTrustedTransport();
        dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR);
        Credential credential = authorize(user);
        oauth2 = new Oauth2.Builder(httpTransport, JSON_FACTORY, credential).setApplicationName(APPLICATION_NAME).build();
        String picture = oauth2.userinfo().get().execute().getPicture();
        //name = oauth2.userinfo().get().execute().getName();
        downloadProfileImage(picture,user.toLowerCase());
        
  } catch (IOException e) {
    System.err.println(e.getMessage());
  } catch (Exception t) {

  }
}
 
開發者ID:Obsidiam,項目名稱:amelia,代碼行數:17,代碼來源:AuthorizeGoogleUser.java

示例3: createClient

import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; //導入方法依賴的package包/類
/**
     * Setup authorization for local app based on private key.
     * See <a href="https://cloud.google.com/pubsub/configure">cloud.google.com/pubsub/configure</a>
     */
    private void createClient(String private_key_file, String email) throws IOException, GeneralSecurityException {
        HttpTransport transport = GoogleNetHttpTransport.newTrustedTransport();
        GoogleCredential credential = new GoogleCredential.Builder()
                .setTransport(transport)
                .setJsonFactory(JSON_FACTORY)
                .setServiceAccountScopes(PubsubScopes.all())
                .setServiceAccountId(email)
                .setServiceAccountPrivateKeyFromP12File(new File(private_key_file))
                .build();
        // Please use custom HttpRequestInitializer for automatic retry upon failures.
//        HttpRequestInitializer initializer = new RetryHttpInitializerWrapper(credential);
        pubsub = new Pubsub.Builder(transport, JSON_FACTORY, credential)
                .setApplicationName("eaipubsub")
                .build();
    }
 
開發者ID:spac3lord,項目名稱:eip,代碼行數:20,代碼來源:PubSubWrapper.java

示例4: GoogleConnector

import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; //導入方法依賴的package包/類
/**
 * Instances the google connector configuring all required resources.
 */
private GoogleConnector() throws IOException, GeneralSecurityException {
    super();
    // 1. JSON library
    jsonFactory = JacksonFactory.getDefaultInstance();

    // 2. Configure HTTP transport
    httpTransport = GoogleNetHttpTransport.newTrustedTransport();

    // 3. Load the credentials
    secrets = GoogleClientSecrets.load(jsonFactory, new InputStreamReader(GoogleConnector.class.getResourceAsStream("client-secrets.json")));

    // 4. Configure the authentication flow
    dataStoreFactory = new FileDataStoreFactory(CREDENTIALS_DIRECTORY);

    // 5. Create flow
    imp_buildAuthorizationFlow();
}
 
開發者ID:dlemmermann,項目名稱:CalendarFX,代碼行數:21,代碼來源:GoogleConnector.java

示例5: getProjectsApiStub

import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; //導入方法依賴的package包/類
/**
 * Return the Projects api object used for accessing the Cloud Resource Manager Projects API.
 * @return Projects api object used for accessing the Cloud Resource Manager Projects API
 * @throws GeneralSecurityException Thrown if there's a permissions error.
 * @throws IOException Thrown if there's an IO error initializing the API object.
 */
public static synchronized Projects getProjectsApiStub()
    throws GeneralSecurityException, IOException {
  if (projectApiStub != null) {
    return projectApiStub;
  }
  HttpTransport transport;
  GoogleCredential credential;
  JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
  transport = GoogleNetHttpTransport.newTrustedTransport();
  credential = GoogleCredential.getApplicationDefault(transport, jsonFactory);
  if (credential.createScopedRequired()) {
    Collection<String> scopes = CloudResourceManagerScopes.all();
    credential = credential.createScoped(scopes);
  }
  projectApiStub = new CloudResourceManager
      .Builder(transport, jsonFactory, credential)
      .build()
      .projects();
  return projectApiStub;
}
 
開發者ID:GoogleCloudPlatform,項目名稱:policyscanner,代碼行數:27,代碼來源:GCPProject.java

示例6: createServiceAccountKeyManager

import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; //導入方法依賴的package包/類
private static ServiceAccountKeyManager createServiceAccountKeyManager() {
  try {
    final HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
    final JsonFactory jsonFactory = Utils.getDefaultJsonFactory();
    final GoogleCredential credential = GoogleCredential
        .getApplicationDefault(httpTransport, jsonFactory)
        .createScoped(IamScopes.all());
    final Iam iam = new Iam.Builder(
        httpTransport, jsonFactory, credential)
        .setApplicationName(SERVICE_NAME)
        .build();
    return new ServiceAccountKeyManager(iam);
  } catch (GeneralSecurityException | IOException e) {
    throw new RuntimeException(e);
  }
}
 
開發者ID:spotify,項目名稱:styx,代碼行數:17,代碼來源:StyxScheduler.java

示例7: build

import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; //導入方法依賴的package包/類
@Override
public DataprocHadoopRunner build() {
  CredentialProvider credentialProvider = Optional.ofNullable(this.credentialProvider)
      .orElseGet(DefaultCredentialProvider::new);

  try {
    final HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
    final JsonFactory jsonFactory = new JacksonFactory();

    final GoogleCredential credentials = credentialProvider.getCredential(SCOPES);
    final Dataproc dataproc = new Dataproc.Builder(httpTransport, jsonFactory, credentials)
        .setApplicationName(APPLICATION_NAME).build();
    final Storage storage = new Storage.Builder(httpTransport, jsonFactory, credentials)
        .setApplicationName(APPLICATION_NAME).build();

    final DataprocClient dataprocClient =
        new DataprocClient(dataproc, storage, projectId, clusterId, clusterProperties);

    return new DataprocHadoopRunnerImpl(dataprocClient);
  } catch (Throwable e) {
    throw Throwables.propagate(e);
  }
}
 
開發者ID:spotify,項目名稱:dataproc-java-submitter,代碼行數:24,代碼來源:DataprocHadoopRunnerImpl.java

示例8: authorize

import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; //導入方法依賴的package包/類
private Sheets authorize() {
  try {
    InputStream in = new FileInputStream(new File(System.getenv("GOOGLE_OATH2_CREDENTIALS")));
    JsonFactory factory = new JacksonFactory();
    GoogleClientSecrets clientSecrets =
        GoogleClientSecrets.load(factory, new InputStreamReader(in, Charset.defaultCharset()));
    HttpTransport transport = GoogleNetHttpTransport.newTrustedTransport();
    FileDataStoreFactory dataStoreFactory =
        new FileDataStoreFactory(new File(dataStoreDirectory));
    List<String> scopes = Collections.singletonList(SheetsScopes.SPREADSHEETS);
    GoogleAuthorizationCodeFlow flow =
        new GoogleAuthorizationCodeFlow.Builder(transport, factory, clientSecrets, scopes)
            .setAccessType("offline")
            .setDataStoreFactory(dataStoreFactory)
            .build();
    Credential credential =
        new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
    return new Sheets.Builder(transport, factory, credential)
        .setApplicationName(APPLICATION_NAME)
        .build();
  } catch (Exception e) {
    return null;
  }
}
 
開發者ID:GoogleCloudPlatform,項目名稱:pubsub,代碼行數:25,代碼來源:SheetsService.java

示例9: getRefreshedCredentials

import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; //導入方法依賴的package包/類
public Credential getRefreshedCredentials(String refreshCode) throws IOException, GeneralSecurityException {
    HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();

    log.info("Getting access token for refresh token..");

    try {
        GoogleTokenResponse response = new GoogleRefreshTokenRequest(
                httpTransport, jsonFactory, refreshCode, clientId, clientSecret )
                .execute();

        return new GoogleCredential().setAccessToken(response.getAccessToken());

    }
    catch( UnknownHostException ex ){
        log.error( "Unknown host. No web access?");
        throw ex;
    }
    catch (IOException e) {
        log.error( "Exception getting refreshed auth: ", e );
    }
    return null;
}
 
開發者ID:Webreaper,項目名稱:GooglePhotoSync,代碼行數:23,代碼來源:GoogleOAuth.java

示例10: getService

import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; //導入方法依賴的package包/類
/**
 * Method to create the service or get the service if is already created.
 *
 * @author <a href="mailto:[email protected]"> João Felipe de Medeiros Moreira </a>
 * @since 13/10/2015
 *
 * @return the Storage service already created.
 *
 * @throws IOException in case a IO problem.
 * @throws GeneralSecurityException in case a security problem.
 */
private static Storage getService() throws IOException, GeneralSecurityException {
  logger.finest("###### Getting the storage service");
  if (null == storageService) {
    HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
    GoogleCredential credential = GoogleCredential.getApplicationDefault();
    // Depending on the environment that provides the default credentials (e.g. Compute Engine,
    // App Engine), the credentials may require us to specify the scopes we need explicitly.
    // Check for this case, and inject the Cloud Storage scope if required.
    if (credential.createScopedRequired()) {
      credential = credential.createScoped(StorageScopes.all());
    }
    storageService = new Storage.Builder(httpTransport, JSON_FACTORY, credential)
        .setApplicationName(APPLICATION_NAME).build();
  }
  return storageService;
}
 
開發者ID:ciandt-dev,項目名稱:tech-gallery,代碼行數:28,代碼來源:StorageHandler.java

示例11: buildService

import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; //導入方法依賴的package包/類
private static Storage buildService() throws IOException, GeneralSecurityException {
  HttpTransport transport = GoogleNetHttpTransport.newTrustedTransport();
  JsonFactory jsonFactory = new JacksonFactory();
  GoogleCredential credential = GoogleCredential.getApplicationDefault(transport, jsonFactory);

  // Depending on the environment that provides the default credentials (for
  // example: Compute Engine, App Engine), the credentials may require us to
  // specify the scopes we need explicitly.  Check for this case, and inject
  // the Cloud Storage scope if required.
  if (credential.createScopedRequired()) {
    Collection<String> scopes = StorageScopes.all();
    credential = credential.createScoped(scopes);
  }

  return new Storage.Builder(transport, jsonFactory, credential)
      .setApplicationName("GCS Samples")
      .build();
}
 
開發者ID:GoogleCloudPlatform,項目名稱:java-docs-samples,代碼行數:19,代碼來源:StorageFactory.java

示例12: setUp

import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
    container = new DefaultComponentRuntimeContainerImpl() {

        @Override
        public String getCurrentComponentId() {
            return TEST_CONTAINER;
        }
    };
    //
    DATA_STORE_DIR = new File(getClass().getClassLoader().getResource("./").toURI().getPath());
    HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
    //
    drive = mock(Drive.class, RETURNS_DEEP_STUBS);
    sourceOrSink = spy(GoogleDriveSourceOrSink.class);
    source = spy(GoogleDriveSource.class);
    sink = spy(GoogleDriveSink.class);
    doReturn(drive).when(sourceOrSink).getDriveService();
    doReturn(drive).when(source).getDriveService();
    doReturn(drive).when(sink).getDriveService();
    //
    emptyFileList = new FileList();
    emptyFileList.setFiles(new ArrayList<com.google.api.services.drive.model.File>());
}
 
開發者ID:Talend,項目名稱:components,代碼行數:25,代碼來源:GoogleDriveTestBaseRuntime.java

示例13: getService

import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; //導入方法依賴的package包/類
private static Storage getService(String credentialsPath, int connectTimeoutMs, int readTimeoutMs) throws Exception {
    if (mStorageService == null) {
        HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();

        GoogleCredential credential;
        try {
            // Lookup if configured path from the properties; otherwise fallback to Google Application default
            if (credentialsPath != null && !credentialsPath.isEmpty()) {
                credential = GoogleCredential
                        .fromStream(new FileInputStream(credentialsPath), httpTransport, JSON_FACTORY)
                        .createScoped(Collections.singleton(StorageScopes.CLOUD_PLATFORM));
            } else {
                credential = GoogleCredential.getApplicationDefault(httpTransport, JSON_FACTORY);
            }
        } catch (IOException e) {
            throw new RuntimeException("Failed to load Google credentials : " + credentialsPath, e);
        }

        mStorageService = new Storage.Builder(httpTransport, JSON_FACTORY,
                setHttpBackoffTimeout(credential, connectTimeoutMs, readTimeoutMs))
                .setApplicationName("com.pinterest.secor")
                .build();
    }
    return mStorageService;
}
 
開發者ID:pinterest,項目名稱:secor,代碼行數:26,代碼來源:GsUploadManager.java

示例14: setup

import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; //導入方法依賴的package包/類
@Before
public void setup()  throws GeneralSecurityException, IOException {
    httpTransport = GoogleNetHttpTransport.newTrustedTransport();

    GoogleCredential googleDirectoryCredential = GoogleAppsSdkUtils.getGoogleDirectoryCredential(SERVICE_ACCOUNT_EMAIL,
                SERVICE_ACCOUNT_PKCS_12_FILE_PATH, SERVICE_IMPERSONATION_USER,
                httpTransport, JSON_FACTORY);

    GoogleCredential googleGroupssettingsCredential = GoogleAppsSdkUtils.getGoogleGroupssettingsCredential(SERVICE_ACCOUNT_EMAIL,
            SERVICE_ACCOUNT_PKCS_12_FILE_PATH, SERVICE_IMPERSONATION_USER,
            httpTransport, JSON_FACTORY);


    directoryClient = new Directory.Builder(httpTransport, JSON_FACTORY, googleDirectoryCredential)
            .setApplicationName("Google Apps Grouper Provisioner")
            .build();

    groupssettingsClient = new Groupssettings.Builder(httpTransport, JSON_FACTORY, googleGroupssettingsCredential)
            .setApplicationName("Google Apps Grouper Provisioner")
            .build();
}
 
開發者ID:Unicon,項目名稱:googleapps-grouper-provisioner,代碼行數:22,代碼來源:GoogleAppsSdkUtilsTest.java

示例15: getCredential

import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; //導入方法依賴的package包/類
/**
 * Return the stored user credential, if applicable, or fall back to the Application Default Credential.
 *
 * @return The com.google.api.client.auth.oauth2.Credential object.
 */
public Credential getCredential() {
  if (hasStoredCredential()) {
    HttpTransport httpTransport;
    try {
      httpTransport = GoogleNetHttpTransport.newTrustedTransport();
    } catch (IOException | GeneralSecurityException e) {
      throw new RuntimeException("Could not create HTTPS transport for use in credential creation", e);
    }

    return new GoogleCredential.Builder()
    .setJsonFactory(JacksonFactory.getDefaultInstance())
    .setTransport(httpTransport)
    .setClientSecrets(getClientId(), getClientSecret())
    .build()
    .setRefreshToken(getRefreshToken());
  }
  return CredentialFactory.getApplicationDefaultCredential();
}
 
開發者ID:googlegenomics,項目名稱:utils-java,代碼行數:24,代碼來源:OfflineAuth.java


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