JSON Problems to recover values

Asked

Viewed 42 times

0

Good guys, I’m kind of Noob in this php subject, I’m developing a dynamic site that videos are on another server so I’m using the API of this site, I have problems when I’m performing a call from JSON already decoded to make a loop of an iframe, it does not impress me any result, I leave the code for you to observe, thank you very much

<?php
$ch = curl_init();
$apiToken = 'zAt7UIgedZtnicMwvKRV1gz39vYlBKEshHQRpOVWahQn4dRyEhLFTF5qJ6ad';

curl_setopt($ch, CURLOPT_URL, "https://api.vidoza.net/v1/files");
$authorization = "Authorization: Bearer ".$apiToken; 

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json' , $authorization )); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$res = curl_exec($ch);
$json = json_decode($res["data"], true);

foreach ($json as $key => $value) {
    echo '
        <IFRAME
            SRC="https://vidoza.net/embed-'.$value["id"].'.html"
            FRAMEBORDER=0 MARGINWIDTH=0 MARGINHEIGHT=0 
            SCROLLING=NO WIDTH=640 HEIGHT=360 allowfullscreen>
         </IFRAME>
    ';
}
?>

1 answer

0


Maybe you’re having problems with the configuration php to access url with SSL.

Try to perform the request by disabling this check with:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

You are also performing json_decode incorrectly. The Decode should be done directly in the raw result.

The final code is as follows::

<?php

$ch         = curl_init();
$apiToken       = 'SEU TOKEN AQUI';
$authorization  = "Authorization: Bearer ".$apiToken; 

curl_setopt($ch, CURLOPT_URL, "https://api.vidoza.net/v1/files");
curl_setopt($ch, CURLOPT_HTTPHEADER, array($authorization )); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

$res = curl_exec($ch);
$json = json_decode($res, true);
curl_close($ch);


foreach ($json['data'] as $key => $value) {
    echo'

    <IFRAME
        SRC="https://vidoza.net/embed-'.$value["id"].'.html"
        FRAMEBORDER=0 MARGINWIDTH=0 MARGINHEIGHT=0 
        SCROLLING=NO WIDTH=640 HEIGHT=360 allowfullscreen>
     </IFRAME>
    ';
}
  • Thank you Vinicius, that’s right, thank you very much for your time...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.