com.google.api.services.sheets.v4.SheetsScopes Java Examples

The following examples show how to use com.google.api.services.sheets.v4.SheetsScopes. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GoogleSheetsAuth.java    From jbpm-work-items with Apache License 2.0 6 votes vote down vote up
public Credential authorize(String clientSecretJSON) throws Exception {
    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY,
                                                                 new StringReader(clientSecretJSON));

    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
            HTTP_TRANSPORT,
            JSON_FACTORY,
            clientSecrets,
            Collections.singleton(SheetsScopes.SPREADSHEETS_READONLY))
            .build();

    return new AuthorizationCodeInstalledApp(flow,
                                             new LocalServerReceiver()).authorize("user");
}
 
Example #2
Source File: GoogleAuthorizeUtil.java    From tutorials with MIT License 5 votes vote down vote up
public static Credential authorize() throws IOException, GeneralSecurityException {
    InputStream in = GoogleAuthorizeUtil.class.getResourceAsStream("/google-sheets-client-secret.json");
    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JacksonFactory.getDefaultInstance(), new InputStreamReader(in));

    List<String> scopes = Arrays.asList(SheetsScopes.SPREADSHEETS);

    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(GoogleNetHttpTransport.newTrustedTransport(), JacksonFactory.getDefaultInstance(), clientSecrets, scopes).setDataStoreFactory(new MemoryDataStoreFactory())
            .setAccessType("offline").build();
    Credential credential = new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");

    return credential;
}