Use following code. It will return you a map of all the query parameters
URL newURL = new URL(GraphURL1);
HttpsURLConnection https = (HttpsURLConnection) newURL.openConnection();
https.setRequestMethod("HEAD");
https.setUseCaches(false);
String query = newURL.getQuery();
Use following code. It will return you a map of all the query parameters
Map<String, String> queryMap = getQueryMap(query );
Method to get query Map
public static Map<String, String> getQueryMap(String query )
{
String[] params = query.split("&");
Map<String, String> map = new HashMap<String, String>();
for (String param : params)
{
String name = param.split("=")[0];
String value = param.split("=")[1];
map.put(name, value);
}
return map;
}
following method will write your token into a file, you just need to pass the token
public void writeTokenIntoFile(String token)
{
try{
File file =new File("c://token.txt");
//if file doesnt exists, then create it
if(!file.exists()){
file.createNewFile();
}
//true = append file
FileWriter fileWritter = new FileWriter(file.getName(),true);
BufferedWriter bufferWritter = new BufferedWriter(fileWritter);
bufferWritter.write(token);
bufferWritter.close();
System.out.println("Done");
}catch(IOException e){
e.printStackTrace();
}
}