Closed almirramic closed 8 months ago
Can you supply source code?
Thanks!
Can you supply source code?
Thanks!
$client = new \PHPFUI\ConstantContact\Client($CCAPIKey, $CCSecret, $CCRedirectURL);
// set any scopes here, defaults to all scopes. Your user will need to accept what ever scopes you specify.
// $client->setScopes(['contact_data', 'campaign_data']);
\header('location: ' . $client->getAuthorizationURL());
$CCAPIKey, $CCSecret, $CCRedirectURL are my variables from db. Checked and rechecked multiple times.
The app goes to the authorization link and returns this _GET on the redirect URL:
?code=vNFtcX_1Y0aM0v14beiOsP8BITKk_wOlcNn-rUh3jRU&state=fe7fdddc43f58fc0
where I do:
$client = new \PHPFUI\ConstantContact\Client($CCAPIKey, $CCSecret, $CCRedirectURL);
$client->acquireAccessToken($_GET);
The class produces no errors of any kind and $client->lastError is empty. No PHP errors either. The class also has the right ids, secret, etc.
Also checked and rechecked things in app definition at app.constantcontact.com.
After your call to acquireAccessToken(), check $client->accessToken and $client->refreshToken. They should be set. Save them to your database, as you will need them to access the API going forward.
Let me know if not.
After your call to acquireAccessToken(), check $client->accessToken and $client->refreshToken. They should be set. Save them to your database, as you will need them to access the API going forward.
Let me know if not.
That is the problem. Like I said, it all seems to work right, except $client->accessToken and $client->refreshToken end up being empty strings.
It could be your session is not set up correctly, or a curl error. Both should return some sort of error that you should see by calling getLastError(). I have had to set up some sort of certificates on my local machine to make curl work in the past.
I would look into the exec method in the client. It is doing most of the work in there.
Let me know what you find and I can add some sort of error logging for it, so the next person who ends up with your error has a better error message.
OK. Thanks. I’ll check and report back.
Awesome. If you want, you could submit a PR for anything you find. See my article on submitting a PR. Gives you all the steps if you have not done one before.
It could be your session is not set up correctly, or a curl error. Both should return some sort of error that you should see by calling getLastError(). I have had to set up some sort of certificates on my local machine to make curl work in the past.
I would look into the exec method in the client. It is doing most of the work in there.
Let me know what you find and I can add some sort of error logging for it, so the next person who ends up with your error has a better error message.
After digging through the code and testing the curl in Client::acquireAccessToken(), I found out that the curl call returned 400 Bad Request. I looked up if others faced the same issue and found this:
So in the Client::acquireAccessToken() function, just before $this->setAuthorization($ch); I added this line:
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['client_id' => $this->clientID, 'client_secret' => $this->clientSecret, 'code' => $_GET['code']]) );
This solved the problem. Not sure why, but i am sure you will find it valuable, especially knowing others have faced the same problem.
I’ll try that. As soon as I catch up. :)
I think I do everything right, the verification returns to my redirect URI, with values in the 'code' and 'state' _GET vars. But the getAuthorizationURL() function does not seem to update the $client class with accessToken and refreshToken, or Constant Contact does not return them or returns empty values. In any case, accessToken and refreshToken are empty. No errors are reported either.
I am on PHP 8.1.21.
Please help.