** 我只想插入我的 curl 令牌的特定欄位:**
我有一個變數將接收這個名為“$r”的令牌,我使用 foreach 來捕獲該值,但我沒有得到它:這就是答案
{
"access_token":"<TOKEN RESPONSE HERE >",
"token_type": "bearer",
"expires_in": 14400
}
下面是我的代碼
<?php
// Generated by curl-to-PHP: http://incarnate.github.io/curl-to-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, "refresh_token=<REFRESH HERE>&grant_type=refresh_token&client_id=<KEY HERE>&client_secret=<SECRET HERE>");
$body = curl_exec($ch);
$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);
}
else{
if (is_array($result) || is_object($result))
{
foreach ($result as $r) {
echo $r['access_token'];
}
}
echo 'Foi: '.$result ;
}
curl_close($ch);
?>
uj5u.com熱心網友回復:
curl_exec回傳一個字串。將其轉換 json_decode($result,1)為關聯陣列
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/512916.html
標籤:php卷曲
