use of com.google.api.client.http.HttpRequest 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;
}
Aggregations