So I try to create a oauth connection with youtube api but I have a problem with decoding the response. My problem is here:
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]);
After I make the exec $resultToken
returns like this:
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) "}" }
But when I try to json_decode to obtain an array: $resultToken = json_decode($resultToken[0]);
I get a result NULL
Can anyone explain to me why please? Any help is welcomed, thank you for your time!
var_dump($resultToken[0]) = NULL;