The objective is to exchange the authorization code for the access and refresh token.
Error:
GuzzleHttp\Exception\ClientException #400
Client error response
[url] http://sandbox.feedly.com/v3/auth/token?code=[auth_code]&client_id=sandbox&client_secret=[secret]&redirect_uri=https%253A%252F%252F[site url]&grant_type=authorization_code&state=%23
[status code] 400
[reason phrase] Bad Request
Related code:
$client = new GuzzleHttp\Client();
$parameters = ['code'=>$_GET['code'],'client_id'=>'sandbox','client_secret'=> '[secret]','redirect_uri'=>urlencode('https://[site url]'),'grant_type'=>'authorization_code', 'state'=>'#'];
$params = http_build_query($parameters);
$request = $client->createRequest('POST', 'http://sandbox.feedly.com/v3/auth/token?'.$params);
$request->addHeader('Accept-Encoding','GZIP');
$request->setHeader('Authorization', "auth-code");
$request->addHeader('Content-Type','application/json');
$response = $client->send($request);
var_dump($response->json());
Also tried with state = "state.passed.in"
but throws same error.
Can you point out the error in the code snippet. It's using the Feedly API v3 sandbox and the Guzzle HTTP client.
If following the request URL, it throws "get not allowed".
Updated code snippet:
$client = new GuzzleHttp\Client();
$parameters = ['code'=>$_GET['code'],'client_id'=>'sandbox','client_secret'=> '[secret]','redirect_uri'=>urlencode('https://[site url]'),'grant_type'=>'authorization_code', 'state'=>'#'];
$params = http_build_query($parameters);
$request = $client->createRequest('POST', 'http://sandbox.feedly.com/v3/auth/token?'.$params);
$response = $client->send($request);
var_dump($response->json());
Error on updated code:
GuzzleHttp\Exception\ServerException #522
Server error response [url] http://sandbox.feedly.com/v3/auth/token?code=[auth_code]&client_id=sandbox&client_secret=[secret]&redirect_uri=https%253A%252F%252F[site url]&grant_type=authorization_code&state=%23
[status code] 522
[reason phrase] Origin Connection Time-out
Note: The update code is throwing the same error (after couple of hours) that is
GuzzleHttp\Exception\ClientException #400
Client error response
[url] http://sandbox.feedly.com/v3/auth/token?code=[auth_code]&client_id=sandbox&client_secret=[secret]&redirect_uri=https%253A%252F%252F[site url]&grant_type=authorization_code&state=%23
[status code] 400
[reason phrase] Bad Request
Problem: The redirect URI is double-encoded that is I am passing https%253A%252F%252Fdev10.ritepush.com%252Fdashboard
, which decodes to https%3A%2F%2Fdev10.ritepush.com%2Fdashboard
. I must encode the uri once that is I need to pass https%3A%2F%2Fdev10.ritepush.com%2Fdashboard
.
Reason: PHP encodes http requests automatically hence upon applying urlencode
to the redirect_uri
, I am actually encoding the redirect URI twice but it is decoded only once. Therefore, the encode URI is passed in the request body which results in the error.
Thanks to David Chatenay from Feedly for pointing out the error.