Thank you very much for the Java example. IT helped me move forward.
I customized it a little bit to get the token, as I was always getting a 406 error.
//////////////////////// ***************** ///////////////////
private String getToken(){
URL url;
String token = null;
String marketoInstance = "https://AAA-BBB-CCC.mktorest.com/identity/oauth/token?grant_type=client_credentials";
String oauthURL = marketoInstance + "&client_id=" + client_id + "&client_secret=" + client_secret;
try {
url = new URL(oauthURL);
HttpsURLConnection urlConn = (HttpsURLConnection) url.openConnection();
if(urlConn!=null){
try {
BufferedReader br = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
for (String x = br.readLine(); x != null; x = br.readLine()) {
x = x.replace("{", "");
x = x.replace("}", "");
String[] content = x.split(",");
for (String tkn : content) {
if(tkn.contains("access_token")){
String temp = tkn.split("\":\"")[1];
if(temp != null){
token = temp.replace("\"", "");
return token;
}
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return token;
}