Zyrd Jan Zyrd Jan - 4 months ago 42
JSON Question

php code trying to echo json data

I have this output and i'am just trying to echo token or store token in a variable

object(stdClass)#1 (9) {
["loggedIn"]=> bool(true)
["token"]=> string(32) "xe5b6bHPPo-_nAvB78NfTpopq9e44bYb"
["secret"]=> string(20) "icCPoDvcf1Vvm2i7-6GM"
["expirationTimestamp"]=> string(24) "2016-11-26T16:32:29.728Z"
["type"]=> string(4) "USER"
["data"]=> object(stdClass)#2 (17)}

here is my code:

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://security.voluum.com/login");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");

$headers = array();
$headers[] = "Authorization: Basic plFubTHhcl93MzA4QHJJkQ9vqmNvwTpMNYYUIz5kcm9s";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);

var_dump(json_decode($result, true));

echo $result->token;
curl_close ($ch);


is the code above correct? how can i extract a single data from the output? please help me

$res_decoded = json_decode($result);
echo $res_decoded->token;