I am trying to refresh access_tokens through basecamp api. But I am facing a strange error.
The cURL request is working fine on POSTMAN (tab: form-data). But I tried every configuration of cURL in PHP, but not able to make it work.
This is the code that I am using:
$refresh_token = func_to_get_refresh_token();
$data='redirect_uri=xxxxmyredirecturixxxx&client_id=xxxxmyclientidxxx&client_secret=xxxxmyclientsecretxxxxx&refresh_token='.$refresh_token.'&type=refresh';
curl_setopt($ch, CURLOPT_URL, 'https://launchpad.37signals.com/authorization/token');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$resp = curl_exec($ch);
I am getting back the following result from Basecamp server :
* upload completely sent off: 448 out of 448 bytes
< HTTP/1.1 400 Bad Request
* Server nginx is not blacklisted
< Server: nginx
< Date: Mon, 09 Feb 2015 08:05:51 GMT
< Content-Type: application/json; charset=utf-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< Status: 400 Bad Request
< X-Request-Id: aaec3a6c61eb5e603672a7a2e004ea7a
< Cache-Control: no-cache
< Set-Cookie: _launchpad_session=BAh7BiIPc2Vzc2lvbl9pZCIlOTEwZTEyOTY0N2M1ZDMxNjM4YjJlZTI2MmRjODE0MTI%3D--7ba9863975db8a7d2c97425300abab8d5405c17a; path=/; HttpOnly; secure
< X-Frame-Options: SAMEORIGIN
< X-Runtime: 0.011202
< Strict-Transport-Security: max-age=31536000
< X-UA-Compatible: IE=Edge,chrome=1
<
* Connection #0 to host launchpad.37signals.com left intact
{"error":"authorization_expired"}
I have already tried almost every configuration of cURL possible from what I can find on stackoverflow.
Your Help will be greatly appreciated.
The following small change did the trick:
$refresh_token = rtrim($refresh_token);
As it turned out, I had to remove the extra invisible character (End Of String character, in this case) before sending it to basecamp.