Skip to content

Instantly share code, notes, and snippets.

@GitEliteNovice
Created July 25, 2019 10:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save GitEliteNovice/09d684ae67c8599363577fd1ee13324b to your computer and use it in GitHub Desktop.
Save GitEliteNovice/09d684ae67c8599363577fd1ee13324b to your computer and use it in GitHub Desktop.
private void sendGetRequestForEmail(String urlString, String accessToken) throws Exception {
URL url = new URL(urlString);
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("Authorization", "Bearer " + accessToken);
con.setRequestProperty("cache-control", "no-cache");
con.setRequestProperty("X-Restli-Protocol-Version", "2.0.0");
BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
StringBuilder jsonString = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
jsonString.append(line);
}
JSONObject jsonObject = new JSONObject(jsonString.toString());
linkedInUserEmailAddress = jsonObject.getJSONArray("elements").getJSONObject(0).getJSONObject("handle~").getString("emailAddress");
Log.d("email json object", jsonObject.toString());
sendRequestToServerForLinkwedInIntegration();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment