Using curl
or file_get_contents
and then using json_decode
.
The result of this:
{"status":200,"msg":"OK","result":{"6PHaY9bqRYc":{"id":"6PHaY9bqRYc","status":200,"name":"big_buck_bunny_720p_1mb.mp4","size":"1055726","sha1":"5b4395dabecd6308ec82bb4f1626f41c40e64654","content_type":"video\/mp4","cstatus":"1"}}}
With json_decode
will be more or less these:
Array
(
[status] => 200
[msg] => OK
[result] => Array
(
[6PHaY9bqRYc] => Array
(
[id] => 6PHaY9bqRYc
[status] => 200
[name] => big_buck_bunny_720p_1mb.mp4
[size] => 1055726
[sha1] => 5b4395dabecd6308ec82bb4f1626f41c40e64654
[content_type] => video/mp4
[cstatus] => 1
)
)
)
Then you will have to use a foreach
also, for example:
<?php
$response = file_get_contents('https://api.openload.co/1/file/info?file=6PHaY9bqRYc');
if (!$response) {
die('Erro nos dados');
}
$data = json_decode($response, true);
if ($data['status'] != 200) {
die('Erro HTTP:' . $data['status']);
}
foreach ($data['result'] as $id => $details) {
echo 'id: ', $details['id'], '<br>';
echo 'Nome: ', $details['name'], '<br>';
echo 'Tamanho: ', $details['size'], '<br>';
echo 'Content-Type: ', $details['content_type'], '<hr>';
}
From the other JSON:
{"status":200,"msg":"OK","result":{"ticket":"valorticket","captcha_url":"valorcaptcha","captcha_w":160,"captcha_h":70,"wait_time":0,"valid_until":"2018-05-11 15:55:44"}}
It should look like this:
<?php
//Esta em string, mas suponho que venha de uma URL
$response = '{"status":200,"msg":"OK","result":{"ticket":"valorticket","captcha_url":"valorcaptcha","captcha_w":160,"captcha_h":70,"wait_time":0,"valid_until":"2018-05-11 15:55:44"}}';
if (!$response) {
die('Erro nos dados');
}
$data = json_decode($response, true);
if ($data['status'] != 200) {
die('Erro HTTP:' . $data['status']);
}
$result = $data['result'];
print_r($result);
echo 'ticket: ', $result['ticket'], PHP_EOL;
echo 'URL captcha: ', $result['captcha_url'], PHP_EOL;
echo 'Largura captcha: ', $result['captcha_w'], PHP_EOL;
echo 'Largura altura: ', $result['captcha_h'], PHP_EOL;
echo 'Validade: ', $result['valid_until'], PHP_EOL;
It does not need foreach
because result
only receives "one object", while the other json received in result:
an object with variant key, for example "6PHaY9bqRYc":
and was still "multi-dimensional".