Skip to content

Commit

Permalink
Changed hardcoded part of API KEY (needs file from now on)
Browse files Browse the repository at this point in the history
  • Loading branch information
platico committed Jul 18, 2016
1 parent d4643cc commit 2593643
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/youtube/YTCommentsCollector.java
Original file line number Diff line number Diff line change
Expand Up @@ -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



Expand Down Expand Up @@ -74,7 +73,7 @@ public ArrayList<JsonObject> 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();
Expand Down Expand Up @@ -127,6 +126,20 @@ public ArrayList<JsonObject> 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
*
Expand Down

0 comments on commit 2593643

Please sign in to comment.