.build(); Drive driveClient = new Drive.Builder(credential.getTransport(), GoogleCommon.getJsonFactory(), Preconditions.checkNotNull(credential, "Credential is required")) .setApplicationName(Preconditions.checkNotNull(wuState.getProp(APPLICATION_NAME), "ApplicationName is required")) .build();
.build(); Drive driveClient = new Drive.Builder(credential.getTransport(), GoogleCommon.getJsonFactory(), Preconditions.checkNotNull(credential, "Credential is required")) .setApplicationName(Preconditions.checkNotNull(wuState.getProp(APPLICATION_NAME), "ApplicationName is required")) .build();
httpRequestInitializer, false); setBatchPath(DEFAULT_BATCH_PATH);
/** * Constructor. * * <p> * Use {@link Builder} if you need to specify any of the optional parameters. * </p> * * @param transport HTTP transport, which should normally be: * <ul> * <li>Google App Engine: * {@code com.google.api.client.extensions.appengine.http.UrlFetchTransport}</li> * <li>Android: {@code newCompatibleTransport} from * {@code com.google.api.client.extensions.android.http.AndroidHttp}</li> * <li>Java: {@link com.google.api.client.googleapis.javanet.GoogleNetHttpTransport#newTrustedTransport()} * </li> * </ul> * @param jsonFactory JSON factory, which may be: * <ul> * <li>Jackson: {@code com.google.api.client.json.jackson2.JacksonFactory}</li> * <li>Google GSON: {@code com.google.api.client.json.gson.GsonFactory}</li> * <li>Android Honeycomb or higher: * {@code com.google.api.client.extensions.android.json.AndroidJsonFactory}</li> * </ul> * @param httpRequestInitializer HTTP request initializer or {@code null} for none * @since 1.7 */ public Drive(com.google.api.client.http.HttpTransport transport, com.google.api.client.json.JsonFactory jsonFactory, com.google.api.client.http.HttpRequestInitializer httpRequestInitializer) { this(new Builder(transport, jsonFactory, httpRequestInitializer)); }
/** * Authorizes the installed application to access user's protected data. */ public static void authorize(String userID, boolean driveAPI) throws IOException { // load client secrets // set up authorization code flow Collection<String> scopes = new ArrayList<String>(); scopes.add(GamesScopes.GAMES); if (driveAPI) scopes.add(DriveScopes.DRIVE_APPDATA); GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY, clientSecrets, scopes).setDataStoreFactory(dataStoreFactory).build(); // authorize Credential credential = new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()) { // Override open browser not working well on Linux and maybe other // OS. protected void onAuthorization(AuthorizationCodeRequestUrl authorizationUrl) throws java.io.IOException { Gdx.net.openURI(authorizationUrl.build()); } }.authorize(userID); games = new Games.Builder(httpTransport, JSON_FACTORY, credential).setApplicationName(applicationName).build(); if (driveAPI) drive = new Drive.Builder(httpTransport, JSON_FACTORY, credential).setApplicationName(applicationName).build(); }
public static void main(String... args) throws IOException, GeneralSecurityException { // Build a new authorized API client service. final NetHttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport(); Drive service = new Drive.Builder(HTTP_TRANSPORT, JSON_FACTORY, getCredentials(HTTP_TRANSPORT)) .setApplicationName(APPLICATION_NAME) .build(); // Print the names and IDs for up to 10 files. FileList result = service.files().list() .setPageSize(10) .setFields("nextPageToken, files(id, name)") .execute(); List<File> files = result.getFiles(); if (files == null || files.isEmpty()) { System.out.println("No files found."); } else { System.out.println("Files:"); for (File file : files) { System.out.printf("%s (%s)\n", file.getName(), file.getId()); } } } }
/** * Initialize file system helper at most once for this instance. * {@inheritDoc} * @see org.apache.gobblin.source.extractor.filebased.FileBasedSource#initFileSystemHelper(org.apache.gobblin.configuration.State) */ @Override public synchronized void initFileSystemHelper(State state) throws FileBasedHelperException { if (fsHelper == null) { Credential credential = new GoogleCommon.CredentialBuilder(state.getProp(SOURCE_CONN_PRIVATE_KEY), state.getPropAsList(API_SCOPES)) .fileSystemUri(state.getProp(PRIVATE_KEY_FILESYSTEM_URI)) .proxyUrl(state.getProp(SOURCE_CONN_USE_PROXY_URL)) .port(state.getProp(SOURCE_CONN_USE_PROXY_PORT)) .serviceAccountId(state.getProp(SOURCE_CONN_USERNAME)) .build(); Drive driveClient = new Drive.Builder(credential.getTransport(), GoogleCommon.getJsonFactory(), credential) .setApplicationName(Preconditions.checkNotNull(state.getProp(APPLICATION_NAME), "ApplicationName is required")) .build(); this.fsHelper = closer.register(new GoogleDriveFsHelper(state, driveClient)); } }
@Override public synchronized void initialize(URI uri, Configuration conf) throws IOException { if (this.client == null) { super.initialize(uri, conf); State state = HadoopUtils.getStateFromConf(conf); Credential credential = new GoogleCommon.CredentialBuilder(state.getProp(SOURCE_CONN_PRIVATE_KEY), state.getPropAsList(API_SCOPES)) .fileSystemUri(state.getProp(PRIVATE_KEY_FILESYSTEM_URI)) .proxyUrl(state.getProp(SOURCE_CONN_USE_PROXY_URL)) .port(state.getProp(SOURCE_CONN_USE_PROXY_PORT)) .serviceAccountId(state.getProp(SOURCE_CONN_USERNAME)) .build(); this.client = new Drive.Builder(credential.getTransport(), GoogleCommon.getJsonFactory(), credential) .setApplicationName(Preconditions.checkNotNull(state.getProp(APPLICATION_NAME), "ApplicationName is required")) .build(); this.pageSize = state.getPropAsInt(PAGE_SIZE, DEFAULT_PAGE_SIZE); } }
@Override protected Drive connect(final Proxy proxy, final HostKeyCallback callback, final LoginCallback prompt) { authorizationService = new OAuth2RequestInterceptor(builder.build(proxy, this, prompt).build(), host.getProtocol()) .withRedirectUri(host.getProtocol().getOAuthRedirectUrl()); final HttpClientBuilder configuration = builder.build(proxy, this, prompt); configuration.addInterceptorLast(authorizationService); configuration.setServiceUnavailableRetryStrategy(new OAuth2ErrorResponseInterceptor(authorizationService)); this.transport = new ApacheHttpTransport(configuration.build()); return new Drive.Builder(transport, json, new HttpRequestInitializer() { @Override public void initialize(HttpRequest request) { request.setSuppressUserAgentSuffix(true); // OAuth Bearer added in interceptor } }) .setApplicationName(useragent.get()) .build(); }
public Drive getDriveService(String appName, String clientSecretJSON) { try { HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport(); Credential credential = authorize(clientSecretJSON); return new Drive.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential) .setApplicationName(appName) .build(); } catch (Exception e) { throw new IllegalArgumentException(e); } }
public static Drive build(Credential credential) throws Exception { final NetHttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport(); return new Drive.Builder(httpTransport, JSON_FACTORY, credential).setApplicationName(APPLICATION_NAME).build(); }
public void init() { try { // authorization Credential credential = authorize(); // set up global Drive instance drive = new Drive.Builder(httpTransport, JSON_FACTORY, credential).setApplicationName(APPLICATION_NAME).build(); logger.info("Google drive webservice client initialized."); } catch (Exception e) { throw new RuntimeException(e); } }
public Drive getDrive(Credential credential) { if(drive == null) { HttpTransport httpTransport = new NetHttpTransport(); drive = new Drive.Builder(httpTransport, getJsonFactory(), credential).setApplicationName("JDriveSync").build(); } return drive; }
public Drive buildDriveService(GoogleCredential credential) throws IOException, GeneralSecurityException { return new Drive.Builder( GoogleNetHttpTransport.newTrustedTransport(), JacksonFactory.getDefaultInstance(), credential) .setApplicationName("Sheets API Snippets") .build(); }
/** * Build and return an authorized Drive client service. * * @return authorized Drive client service * @throws GeneralSecurityException when credentials fails * @throws IOException when credentials fails */ public Drive getDriveService() throws GeneralSecurityException, IOException { return new Drive.Builder(getHttpTransport(), JacksonFactory.getDefaultInstance(), getCredential()) .setApplicationName(getApplicationName()).build(); }
public void createDriver() throws IOException { try { HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport(); } catch (GeneralSecurityException e) { logger.error("Create Driver Error", e); } DATA_STORE_FACTORY = new FileDataStoreFactory(DATA_STORE_DIR); Credential credential = authorize(); drive = new Drive.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential).setApplicationName( APPLICATION_NAME).build(); }
public Drive buildDriveService(GoogleCredential credential) throws IOException, GeneralSecurityException { return new Drive.Builder( GoogleNetHttpTransport.newTrustedTransport(), JacksonFactory.getDefaultInstance(), credential) .setApplicationName("Slides API Snippets") .build(); }
public static Drive getService(byte[] credsFile) throws IOException { return new Drive.Builder(getHttpTransport(), getJsonFactory(), authorize(credsFile)) .setApplicationName(getApplicationName()) .build(); } }
public static Drive createDriveService(final Credential credential, final HttpTransport transport) { return new Drive.Builder(transport, JSON_FACTORY, credential) .setApplicationName(APPLICATION_NAME) .build(); }
/** * Build and return an authorized Drive client service. * * @return authorized Drive client service * @throws GeneralSecurityException when credentials fails * @throws IOException when credentials fails */ public Drive getDriveService() throws GeneralSecurityException, IOException { return new Drive.Builder(getHttpTransport(), JacksonFactory.getDefaultInstance(), getCredential()) .setApplicationName(getApplicationName()).build(); }