Search in sources :

Example 11 with HttpRequestInitializer

use of com.google.api.client.http.HttpRequestInitializer in project local-data-aragopedia by aragonopendata.

the class GoogleDriveAPI method authorize.

/**
	 * Creates an authorized Credential object.
	 * 
	 * @return an authorized Credential object.
	 * @throws IOException
	 * @throws GeneralSecurityException
	 */
private static GoogleCredential authorize() throws IOException, GeneralSecurityException {
    HttpTransport httpTransport = new NetHttpTransport();
    httpTransport = httpTransport.createRequestFactory().getTransport();
    HttpRequestInitializer httpRequestInitializer = new HttpRequestInitializer() {

        @Override
        public void initialize(HttpRequest httpRequest) throws IOException {
            httpRequest.setConnectTimeout(300 * 60000);
            httpRequest.setReadTimeout(300 * 60000);
        }
    };
    JacksonFactory jsonFactory = new JacksonFactory();
    GoogleCredential credential = new GoogleCredential.Builder().setRequestInitializer(httpRequestInitializer).setTransport(httpTransport).setJsonFactory(jsonFactory).setServiceAccountId(Prop.acountId).setServiceAccountScopes(SCOPES).setServiceAccountPrivateKeyFromP12File(new java.io.File(Prop.p12File)).build();
    return credential;
}
Also used : HttpRequest(com.google.api.client.http.HttpRequest) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) HttpTransport(com.google.api.client.http.HttpTransport) GoogleNetHttpTransport(com.google.api.client.googleapis.javanet.GoogleNetHttpTransport) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) GoogleNetHttpTransport(com.google.api.client.googleapis.javanet.GoogleNetHttpTransport) GoogleCredential(com.google.api.client.googleapis.auth.oauth2.GoogleCredential) HttpRequestInitializer(com.google.api.client.http.HttpRequestInitializer) JacksonFactory(com.google.api.client.json.jackson2.JacksonFactory) File(com.google.api.services.drive.model.File)

Aggregations

HttpRequestInitializer (com.google.api.client.http.HttpRequestInitializer)11 HttpRequest (com.google.api.client.http.HttpRequest)8 IOException (java.io.IOException)5 GoogleCredential (com.google.api.client.googleapis.auth.oauth2.GoogleCredential)3 GenericUrl (com.google.api.client.http.GenericUrl)3 HttpRequestFactory (com.google.api.client.http.HttpRequestFactory)3 HttpTransport (com.google.api.client.http.HttpTransport)3 NetHttpTransport (com.google.api.client.http.javanet.NetHttpTransport)3 GoogleJsonResponseException (com.google.api.client.googleapis.json.GoogleJsonResponseException)2 HttpResponse (com.google.api.client.http.HttpResponse)2 YouTube (com.google.api.services.youtube.YouTube)2 SearchListResponse (com.google.api.services.youtube.model.SearchListResponse)2 SearchResult (com.google.api.services.youtube.model.SearchResult)2 Credentials (com.google.auth.Credentials)2 HttpCredentialsAdapter (com.google.auth.http.HttpCredentialsAdapter)2 PluginTestVerifier (com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier)2 InputStream (java.io.InputStream)2 Method (java.lang.reflect.Method)2 Properties (java.util.Properties)2 Test (org.junit.Test)2