当前位置: 首页>>代码示例>>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;未经允许,请勿转载。