Device Flow Refresh Token

HelpingHandsAct
Rookie
0 Votes
Hi, I'm following the 6/6/2023 reply from John__B; https://community.constantcontact.com/t5/API-Developer-Support/Device-Flow-Refresh-Token/m-p/404332#... and wrote this refresh token function in PHP; function refreshToken($refreshToken, $clientId, $connection) { $ch = curl_init(); // Define endpoint URL $url = 'https://authz.constantcontact.com/oauth2/default/v1/token'; // Set up the POST fields $postData = [ 'refresh_token' => $refreshToken, 'grant_type' => 'refresh_token', 'client_id' => $clientId ]; curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData)); // Set other cURL options curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded')); // Execute and return the response $result = curl_exec($ch); if (curl_errno($ch)) { return 'Error:' . curl_error($ch); } curl_close($ch); $responseData = json_decode($result, true); // Convert the JSON string to an associative array $accessToken = $responseData['access_token']; // Get the access_token value setAuthToken($connection, $accessToken); return $accessToken; } and it returns "The refresh token is invalid or expired". When I get my original token, I receive; {"token_type":"Bearer","expires_in":86400,"access_token":"","scope":"openid contact_data","id_token":"}. Is the refresh token the "id_token"? Is my function correct and I'm receiving the refresh token invalid because I waited too long to refresh my token? Thank you in advance for your help. Best Regards, Brian
1 REPLY 1
Courtney_E
Employee
0 Votes

Hello HelpingHandsAct,

 

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.

 

Based on what you are experiencing, it looks like the refresh token is most likely not being stored correctly as a variable within the application.

 

If you continue to run into issues, could you please contact us directly/securely via email  at webservices@constantcontact.com (do not post sensitive info in the community) and provide us with the API key that you are using to make the request, the full request(s) where you are receiving the response (including URL, headers, timestamp, and request body), and the full response body so that we can better assist you in identifying the root cause of the issue?

 

While our expertise is with our API itself as opposed to its implementation within any particular programming language, we are happy to answer any questions pertaining to Constant Contact’s API endpoints, functionality, and documentation.

 

Please have a look and let us know if you have any other questions!


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