From 2593643d4e0ff60556b9e7f370b58d7667802445 Mon Sep 17 00:00:00 2001 From: platico Date: Mon, 18 Jul 2016 13:14:32 +0300 Subject: [PATCH] Changed hardcoded part of API KEY (needs file from now on) --- src/youtube/YTCommentsCollector.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/youtube/YTCommentsCollector.java b/src/youtube/YTCommentsCollector.java index 38ac71e..6fa0a17 100644 --- a/src/youtube/YTCommentsCollector.java +++ b/src/youtube/YTCommentsCollector.java @@ -37,7 +37,6 @@ public class YTCommentsCollector { private static YouTube youtube; private static JsonBuilderFactory factory = Json.createBuilderFactory(null); private static final HttpClient defaultHttpClient = HttpClients.createDefault(); - private static final String API_KEY = "AIzaSyC3tKP3j78TJNG9CqxujOeoUrZrqB_ewfY"; //the api key @@ -74,7 +73,7 @@ public ArrayList collectComments(String filenameArgument) { String[] splitted = userURL.split("/"); String userID = splitted[splitted.length-1]; //gets the user ID - String url = String.format("https://www.googleapis.com/plus/v1/people/"+userID+"?key="+API_KEY); //creates the user api URL + String url = String.format("https://www.googleapis.com/plus/v1/people/"+userID+"?key="+readAPIKey()); //creates the user api URL HttpGet httpGet = new HttpGet(url); HttpEntity entity = defaultHttpClient.execute(httpGet).getEntity(); @@ -127,6 +126,20 @@ public ArrayList collectComments(String filenameArgument) { return jsons; //returns the jsons } + private String readAPIKey(){ + try { + BufferedReader bufferedReader = new BufferedReader(new FileReader("API_KEY.txt")); + String key = bufferedReader.readLine(); //key is in the string in the first line of the API_KEY.txt file + bufferedReader.close(); + return key; + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return ""; + } + /** * Method responsible for getting the user details from JSON *