// ---------------------------------------------------------------------------------------------------------------- // Method: authorize // Inputs: none // Outputs: Credentials // Description: Creates an authorized credential object, will throw IO exception // ---------------------------------------------------------------------------------------------------------------- private static Credential authorize() throws IOException { // Load client secrets (from JSON file) InputStream in = Main.class.getResourceAsStream("/client_secret_ecen689project1.json"); GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in)); // Build flow and trigger user authorization request GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder( HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, Collections.singleton(FusiontablesScopes.FUSIONTABLES)) .setDataStoreFactory(DATA_STORE_FACTORY) .build(); // Authorize and get the credential Credential credential = new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user"); System.out.println("Credentials saved to " + DATA_STORE_DIR.getAbsolutePath()); return credential; // Return the credential }