Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

127
Visualizações
¿Cómo abro el servicio GoogleSheets con un token de actualización almacenado usando la API de Java v4?

Estoy trabajando en una aplicación (Apache Drill) y busco crear un conector para Hojas de cálculo de Google utilizando la API de Java de Google (v4).

Tengo esto funcionando, sin embargo, me gustaría almacenar el token de actualización y aquí es donde estoy atascado. Aquí está mi código existente:

 public static Credential authorize(GoogleSheetsStoragePluginConfig config) throws IOException, GeneralSecurityException { GoogleClientSecrets clientSecrets = config.getSecrets(); GoogleAuthorizationCodeFlow flow; List<String> scopes = Collections.singletonList(SheetsScopes.SPREADSHEETS); flow = new GoogleAuthorizationCodeFlow.Builder (GoogleNetHttpTransport.newTrustedTransport(), JSON_FACTORY, clientSecrets, scopes) .setDataStoreFactory(config.getDataStoreFactory()) .setAccessType("offline") .build(); return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user"); } public static Sheets getSheetsService(GoogleSheetsStoragePluginConfig config) throws IOException, GeneralSecurityException { Credential credential = GoogleSheetsUtils.authorize(config); return new Sheets.Builder( GoogleNetHttpTransport.newTrustedTransport(), GsonFactory.getDefaultInstance(), credential) .setApplicationName("Drill") .build(); }

Lo que me gustaría tener es algo como esto:

 public static Sheets getSheetsService(<client secrets>, String refreshToken, String accessToken) { // Not sure what to do here... } Any help would be greatly appreciated.
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

La biblioteca del cliente java api de Google está diseñada para manejar todo esto por usted. De manera predeterminada, FileDataStoreFactory almacena todas las credenciales en un archivo en su máquina en DATA_STORE_DIR.

 dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR);

Si no desea almacenarlo en un archivo, solo necesita crear su propia implementación de AbstractDataStoreFactory que aceptará su token de actualización.

Ejemplo completo de FileDataStoreFactory

 /** * Initializes an authorized sheets service object. * * @return The sheets service object. * @throws IOException * @throws GeneralSecurityException */ private static Sheets initializeAnalyticsReporting() throws GeneralSecurityException, IOException { httpTransport = GoogleNetHttpTransport.newTrustedTransport(); dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR); // Load client secrets. GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(HelloSheets.class .getResourceAsStream(CLIENT_SECRET_JSON_RESOURCE))); // Set up authorization code flow for all authorization scopes. GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow .Builder(httpTransport, JSON_FACTORY, clientSecrets, SheetsScopes.all()).setDataStoreFactory(dataStoreFactory) .build(); // Authorize. Credential credential = new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user"); // Construct the sheets service object. return new Sheets.Builder(httpTransport, JSON_FACTORY, credential) .setApplicationName(APPLICATION_NAME).build(); }
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda