目標是交換訪問和刷新令牌的授權碼。對Feedly API的授權請求會使用Guzzle拋出一個錯誤的請求?
錯誤:
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
相關代碼:
$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());
與state = "state.passed.in"
也試過,但會引發同樣的錯誤。
你能指出代碼片段中的錯誤嗎?它使用Feedly API v3沙盒和Guzzle HTTP客戶端。
如果跟隨請求URL,它會拋出「不允許」。
更新程式碼:
$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());
錯誤的更新代碼:
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
注:更新代碼拋出了同樣的錯誤(幾個小時後),即
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
522狀態碼不是標準的,我知道CloudFare使用它來表示服務器連接超時,所以這可能是Feedly服務器上的問題。請參見[Error-522-Connection-timeoutd-out](https://support.cloudflare.com/hc/en-us/articles/200171906-Error-522-Connection-timed-out)。 –
感謝您的解釋。這很有幫助。我更新了代碼,並得到一個'[status code] 522 [reason phrase] Origin Connection Time-out error'。我在問題中添加了更新的代碼和錯誤。我仔細查看了錯誤的細節,發現它是服務器端錯誤。你能澄清一下錯誤嗎?是否有一些修復(如果我失去了一些東西)我可以從我身邊申請嗎? –
更新後的代碼出現同樣的錯誤:嘗試了幾個小時後,[[status code] 400 [reason phrase] Bad Request']。 522錯誤現在不會提出。你能否解釋一下這個問題? –