Vit*_*Vit -2 php json google-api laravel gmail-api
请帮我解码并获取access_token。已经检查了 30 多篇 stackoverflow 帖子json_decode
所以首先是Curl. 这些参数不影响 json 响应和解码:curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'); curl_setopt($ch, CURLOPT_VERBOSE, 1);
标头输出显示它是 utf8 响应。
它没有“&”或反斜杠
$jsonData = curl_exec($ch);然后var_dump($jsonData)- 说 Google 返回了boolean这是ddLaravel 中的结果:
之后的代码Curl
....
$jsonData = curl_exec($ch);
if ($jsonData === null && json_last_error() !== JSON_ERROR_NONE) {
echo "json data is incorrect";
}
dd(
var_dump($jsonData),// tell me it is "bool(true)", after json end}
'json_decode results:',
json_decode($jsonData),
json_decode($jsonData,1),
json_decode( ( stripslashes($jsonData) ),1),
json_decode( trim ( stripslashes($jsonData) ),1),
json_decode( preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $jsonData), 0 ),
json_decode( preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $jsonData), 1 )
);
Run Code Online (Sandbox Code Playgroud)
也json_decode( trim($jsonData) );没有帮助
如果您拥有的是布尔值,那么再多的解码也无法神奇地恢复更多数据。你的问题出在你的curl代码中——返回布尔值的不是Google,而是函数curl_exec。
这是因为默认情况下,curl显示接收到的数据,并返回true 表示成功。您需要添加此选项:
curl_setopt(CURLOPT_RETURNTRANSFER, true);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
145 次 |
| 最近记录: |