Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

48
LINES

< > BotCompany Repo | #1028553 // GoogleAccess

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Uses 4337K of libraries. Click here for Pure Java version (2875L/17K).

ifndef NoLib1400401
lib 1400401
endifndef

import com.google.api.client.googleapis.auth.oauth2.*;

import com.google.api.client.auth.oauth2.Credential;
import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow;
import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;

sclass GoogleAccess {
  GoogleCredential credential;
  
  simplyCached HttpTransport transport() ctex {
    ret GoogleNetHttpTransport.newTrustedTransport();
  }
  
  simplyCached JsonFactory jsonFactory() ctex {
    ret JacksonFactory.getDefaultInstance();
  }
  
  simplyCached GoogleClientSecrets clientSecrets() ctex {
    temp InputStream in = newFileInputStream(javaxSecretDir("google-botcompany-credentials.json"));
    ret GoogleClientSecrets.load(jsonFactory(), new InputStreamReader(in));
  }

  GoogleCredential credentialFromTokens(S accessToken, S refreshToken) {
    ret credential = new GoogleCredential.Builder()
      .setTransport(transport())
      .setJsonFactory(jsonFactory())
      .setClientSecrets(clientSecrets())
      .build()
      .setAccessToken(accessToken)
      .setRefreshToken(refreshToken);
  }
  
  GoogleCredential credentialFromJavaXSecret() ctex {
    ret GoogleCredential.fromStream(
      fileInputStream(assertFileExists(javaxSecretDir("google-access.json")));
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1028553
Snippet name: GoogleAccess
Eternal ID of this version: #1028553/8
Text MD5: b7c2576061a3d8edd62a35065b05e7d7
Transpilation MD5: ec19ad2869517378265769102dd4329d
Author: stefan
Category: javax
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-01-14 02:58:46
Source code size: 1819 bytes / 48 lines
Pitched / IR pitched: No / No
Views / Downloads: 307 / 1145
Version history: 7 change(s)
Referenced in: #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674)