I get authorization codes without issue but when using the following code I only get the response below.
<html> <head><title>400 Bad Request</title></head> <body> <center><h1>400 Bad Request</h1></center> <hr><center>cloudflare</center> </body> </html>
The code I am using to call for the access token is below.
// Use cURL to get access token and refresh token $ch = curl_init(); // Define base URL $base = 'https://authz.constantcontact.com/oauth2/default/v1/token'; // Create full request URL $url = $base . '?code=' . $_GET['code'] . '&redirect_uri=' . urlencode(DOMAIN.'connect/constantcontact/') . '&grant_type=authorization_code'; //echo $url; curl_setopt($ch, CURLOPT_URL, $url); // Set authorization header // Make string of "API_KEY:SECRET" $auth = $this->_clientID . ':' . $this->_clientSecret; //echo $auth; // Base64 encode it $credentials = base64_encode($auth); // Create and set the Authorization header to use the encoded credentials, and set the Content-Type header $authorization = 'Authorization: Basic ' . $credentials; curl_setopt($ch, CURLOPT_HTTPHEADER, array($authorization, 'Accept: application/json', 'Content-Type: application/x-www-form-urlencoded')); // Set method and to expect response curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Make the call $result = curl_exec($ch); curl_close($ch); print_r($result);
Any ideas on what could be causing this? We are following the docs exactly...
I solved this by adding the following to the post body
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['client_id' => $this->_clientID, 'client_secret' => $this->_clientSecret, 'code' => $_GET['code']]) );
Thank you for reaching out to Constant Contact API Developer Support. My team is here to assist outside software developers with questions about building into Constant Contact's API.
I'm glad to hear you were able to resolve your problem!
If you run into any other issues going forward, please feel free to contact out team directly (if desired) at firstname.lastname@example.org
View API documentation, code samples, get your API key.Visit Page
Join our list to be notified of new features and updates to our V3 API.Sign Up