下午好!我是 PHP 編程的新手,我希望有人幫助我如何在 Php Curl 中從 Dropbox API 撰寫這個重繪 令牌請求。我已經閱讀了有關 PHP Curl 的官方檔案,但我沒有理解它。
Curl(終端)中的 Dropbox API 請求:
curl https://api.dropbox.com/oauth2/token \
-d grant_type=refresh_token \
-d refresh_token=<REFRESH_TOKEN> \
-u <APP_KEY>:<APP_SECRET>
其中 <APP_KEY>、<APP_SECRET> 和 REFRESH_TOKEN 是從 Dropbox 獲得的憑據。
我如何在 PHP Curl 中撰寫這個?
它將回傳一個帶有來自 Dropbox 的新 Oauth2 訪問令牌的 json 輸出,我想學習如何處理這個輸出。
uj5u.com熱心網友回復:
對于 PHP Http 請求的初學者,你可以使用這個 Curl 到 PHP Curl 翻譯,Wich 將你的 Curl 請求翻譯成 PHP 代碼。
https://incarnate.github.io/curl-to-php/
這對我來說效果很好。
看看你的 Curl 命令在 PHP 中的表現如何
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.dropbox.com/oauth2/token');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=refresh_token&refresh_token=<REFRESH_TOKEN>");
curl_setopt($ch, CURLOPT_USERPWD, '<APP_KEY>' . ':' . '<APP_SECRET>');
$headers = array();
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/492496.html
