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


Java GoogleNetHttpTransport類代碼示例

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


GoogleNetHttpTransport類屬於com.google.api.client.googleapis.javanet包,在下文中一共展示了GoogleNetHttpTransport類的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: getServiceAccountsApiStub

import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; //導入依賴的package包/類
/**
 * Get the API stub for accessing the IAM Service Accounts API.
 * @return ServiceAccounts api stub for accessing the IAM Service Accounts API.
 * @throws IOException Thrown if there's an IO error initializing the api connection.
 * @throws GeneralSecurityException Thrown if there's a security error
 * initializing the connection.
 */
public static ServiceAccounts getServiceAccountsApiStub() throws IOException, GeneralSecurityException {
  if (serviceAccountsApiStub == null) {
    HttpTransport transport;
    GoogleCredential credential;
    JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
    transport = GoogleNetHttpTransport.newTrustedTransport();
    credential = GoogleCredential.getApplicationDefault(transport, jsonFactory);
    if (credential.createScopedRequired()) {
      Collection<String> scopes = IamScopes.all();
      credential = credential.createScoped(scopes);
    }
    serviceAccountsApiStub = new Iam.Builder(transport, jsonFactory, credential)
        .build()
        .projects()
        .serviceAccounts();
  }
  return serviceAccountsApiStub;
}
 
開發者ID:GoogleCloudPlatform,項目名稱:policyscanner,代碼行數:26,代碼來源:GCPServiceAccount.java

示例7: 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

示例8: 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

示例9: getGoogleComputeClient

import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; //導入依賴的package包/類
/**
 * Get a Google Compute Engine client object.
 * @param userEmail The service account's client email.
 * @param privateKey The service account's private key.
 * @param scopes The scopes used in the compute client object.
 * @param applicationName The application name.
 * @return The created Compute Engine client object.
 * @throws GeneralSecurityException Exception when creating http transport.
 * @throws IOException Exception when creating http transport.
 */
public static Compute getGoogleComputeClient(String userEmail,
                                             String privateKey,
                                             List<String> scopes,
                                             String applicationName)
        throws GeneralSecurityException, IOException {
    HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
    GoogleCredential credential = new GoogleCredential.Builder()
            .setTransport(httpTransport)
            .setJsonFactory(JSON_FACTORY)
            .setServiceAccountId(userEmail)
            .setServiceAccountScopes(scopes)
            .setServiceAccountPrivateKey(privateKeyFromPkcs8(privateKey))
            .build();
    return new Compute.Builder(httpTransport, JSON_FACTORY, credential)
            .setApplicationName(applicationName)
            .build();
}
 
開發者ID:vmware,項目名稱:photon-model,代碼行數:28,代碼來源:GCPTestUtil.java

示例10: getSensorEndpoint

import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; //導入依賴的package包/類
/**
    * Create a Sensor API client instance
    * @return
    * @throws IOException 
    * @throws GeneralSecurityException 
    */
private static Sensor getSensorEndpoint() throws IOException {
	
	CmdLineAuthenticationProvider provider = new CmdLineAuthenticationProvider();
	// see https://developers.google.com/api-client-library/java/
	provider.setClientSecretsFile("client_secret.json");
	provider.setScopes(SCOPES);
	
	// get the oauth credentials
	Credential credential = provider.authorize();
	
	// initialize the transport
	HttpTransport httpTransport;
       try {
           httpTransport = GoogleNetHttpTransport.newTrustedTransport();
       } catch (GeneralSecurityException e) {
           log.log(Level.SEVERE, "failed to create transport", e);
           throw new IOException(e);
       }

	return new Sensor.Builder(httpTransport, JacksonFactory.getDefaultInstance(), credential)
			.setApplicationName(APP_NAME).setRootUrl(DEFAULT_ROOT_URL).build();

}
 
開發者ID:omerio,項目名稱:raspberrypi-app,代碼行數:30,代碼來源:RaspberryPiApp.java

示例11: createAdminApiClient

import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; //導入依賴的package包/類
private static SQLAdmin createAdminApiClient(Credential credential) {
  HttpTransport httpTransport;
  try {
    httpTransport = GoogleNetHttpTransport.newTrustedTransport();
  } catch (GeneralSecurityException | IOException e) {
    throw new RuntimeException("Unable to initialize HTTP transport", e);
  }

  String rootUrl = System.getProperty(API_ROOT_URL_PROPERTY);
  String servicePath = System.getProperty(API_SERVICE_PATH_PROPERTY);

  JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
  SQLAdmin.Builder adminApiBuilder =
      new Builder(httpTransport, jsonFactory, credential)
          .setApplicationName("Cloud SQL Java Socket Factory");
  if (rootUrl != null) {
    logTestPropertyWarning(API_ROOT_URL_PROPERTY);
    adminApiBuilder.setRootUrl(rootUrl);
  }
  if (servicePath != null) {
    logTestPropertyWarning(API_SERVICE_PATH_PROPERTY);
    adminApiBuilder.setServicePath(servicePath);
  }
  return adminApiBuilder.build();
}
 
開發者ID:GoogleCloudPlatform,項目名稱:cloud-sql-jdbc-socket-factory,代碼行數:26,代碼來源:SslSocketFactory.java

示例12: getApiService

import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; //導入依賴的package包/類
/**
 * Get an instance of the language service.
 *
 * @param document
 * @return
 */
public CloudNaturalLanguageAPI getApiService(GoogleCredential credential) {
  final GoogleCredential cred = credential;
  CloudNaturalLanguageAPI api = null;
  try {
    api = new CloudNaturalLanguageAPI.Builder(
            GoogleNetHttpTransport.newTrustedTransport(),
            JacksonFactory.getDefaultInstance(),
            new HttpRequestInitializer() {
      @Override
      public void initialize(HttpRequest httpRequest) throws IOException {
        cred.initialize(httpRequest);
      }
    }).setApplicationName(getApplicationName()).build();
  } catch (Exception ex) {
    throw new GateRuntimeException("Could not establish Google Service API", ex);
  }
  //System.err.println("DEBUG: API instance established: " + api);
  return api;
}
 
開發者ID:GateNLP,項目名稱:gateplugin-Tagger_GoogleNLP,代碼行數:26,代碼來源:TaggerGoogleNLP.java

示例13: init

import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; //導入依賴的package包/類
public GoogleCalendarSync init() throws Exception {
    // initialize the transport
    httpTransport = GoogleNetHttpTransport.newTrustedTransport();

    // initialize the data store factory
    dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR);

    // authorization
    final Credential credential = authorize();

    // set up global Calendar instance
    client = new com.google.api.services.calendar.Calendar.Builder(httpTransport, JSON_FACTORY, credential)
            .setApplicationName(APPLICATION_NAME).build();

    return this;
}
 
開發者ID:DrBookings,項目名稱:drbookings,代碼行數:17,代碼來源:GoogleCalendarSync.java

示例14: 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

示例15: getGmailService

import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; //導入依賴的package包/類
private static Gmail getGmailService(String basedir, String appName) throws Exception {

        // 機密情報ファイルのパス
        File DATA_STORE_DIR = new java.io.File(basedir, "gmail-secrets");
        File SECRET_JSON = new java.io.File(DATA_STORE_DIR, "client_secret.json");

        // 準備
        FileDataStoreFactory DATA_STORE_FACTORY = new FileDataStoreFactory(DATA_STORE_DIR);
        JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
        HttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();

        // 送信のみ
        List<String> SCOPES = Arrays.asList(GmailScopes.GMAIL_SEND);

        // Credential取得
        try (InputStream in = FileUtils.openInputStream(SECRET_JSON)) {
            GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));
            GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY,
                    clientSecrets, SCOPES).setDataStoreFactory(DATA_STORE_FACTORY).setAccessType("offline").build();
            Credential credential = new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");

            // Gmailインスタンス生成
            return new Gmail.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential).setApplicationName(appName).build();
        }
    }
 
開發者ID:af-not-found,項目名稱:blog-java2,代碼行數:26,代碼來源:SmtpManager.java


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