Join our Ask A Trainer Sessions and Chat With our Experts!

Unable to get access token

toddp198
Rookie
0 Votes
I believe I've followed the docs, but am getting a 400 status code when trying to get an access token.  I've created the API code and call the following URL to get the auth code:   

// https://api.cc.email/v3/idfed?client_id=22c<redacted>2c3b&redirect_uri=https%3A%2F%2Flocalhost&response_type=code&scope=account_read+account_update+contact_data



private HashMap< String , String > headersMap = new HashMap<>();

public static void main( String[] args ) throws IOException {

ConstantContactUtilities constantContactUtilities = new ConstantContactUtilities();
constantContactUtilities.getAuthCodeFromAccessTokenAndRefreshToken();

}


public ConstantContactUtilities() {

// apiKey and clientId are the same field. Stupid ConstantContact uses both terms for the same thing
String apiKey = "22c<redacted>2c3b";
String clientSecret = "RPd<redacted>jCQ";

String credentials = apiKey + ":" + clientSecret;
String authorization = "Basic " + Base64.getEncoder().encodeToString(credentials.getBytes());

headersMap.put( "Authorization" , authorization );
}


public void getAuthCodeFromAccessTokenAndRefreshToken() throws IOException {

String authCode = "Bo090<redacted>8NQAEt";

HttpUtilities httpUtilities = HttpUtilities.getInstance();
String url = "https://idfed.constantcontact.com/as/token.oauth2?code=" + authCode +
"&redirect_uri=https://localhost&grant_type=authorization_code";
HttpResponse httpResponse = httpUtilities.doPost( url , headersMap , new HashMap< String , String >() );
System.out.println( httpResponse.getStatusLine() ); <-- 400 status code
}
}

What am I doing wrong?

 

1 REPLY 1
Courtney_E
Moderator
0 Votes

Hello Todd,

 

It looks like we already reached out to you via email regarding this issue to request some additional information in order to assist in troubleshooting. If you still need assistance with this, please let us know!


Regards,

Courtney E.
Tier II API Support Engineer

Did I answer your question?
If so, please mark my post as an "Accepted Solution" by clicking the Accept as Solution button in the bottom right hand corner of this post.
Resources
Developer Portal

View API documentation, code samples, get your API key.

Visit Page

Announcements

API Updates

Join our list to be notified of new features and updates to our V3 API.

Sign Up