1
因此,我尝试创建与YouTube API的oauth连接,但我有解码响应的问题。我的问题是在这里:json_decode返回null当我尝试解码来自YouTube的api的响应
public function getCallbackUrl($code)
{
// Grab the returned code and extract the access token.
$this->params = [
'code' => $code,
'client_id' => '#####',
'client_secret' => '####',
'redirect_uri' => '######',
'grant_type' => 'authorization_code'
];
// Get access token
$command = 'curl --data "' . http_build_query($this->params) . '" https://accounts.google.com/o/oauth2/token';
exec($command, $resultToken);
$resultToken = json_decode($resultToken[0]);
我做高管$resultToken
回报这样的后:
array(5) { [0]=> string(1) "{" [1]=> string(93) " "access_token" : "###########"," [2]=> string(26) " "token_type" : "Bearer"," [3]=> string(21) " "expires_in" : 3599" [4]=> string(1) "}" }
但是当我尝试json_decode获得一个数组:$resultToken = json_decode($resultToken[0]);
我得到的结果NULL
任何人都可以向我解释为什么请说吧?欢迎任何帮助,谢谢你的时间!
var_dump($resultToken[0]) = NULL;
var_dump($ resultToken [0])是什么? –
是的,向我们展示响应主体。 –
'$ resultToken [0]'是无效的JSON。检查你的回应。另外考虑使用[PHP cURL扩展名](https://php.net/curl),而不是直接使用系统调用。 – Elias