从habbo的json页面获取内容

时间:2016-08-09 16:56:41

标签: php json http curl file-get-contents

我正在尝试获取网页内容以在我的网站上使用它。

我需要this链接中的内容。

然后我想从json页面获取“figureString”, 所以我可以把它放在this链接中。

我尝试使用curl但它说他们因为ddos尝试阻止了我。 我不能使用file_get_contents,它说无法打开流:HTTP请求失败! get_remote_data也不起作用。

<?php
echo "WELCOME ".$r->habboname;

$curl_handle=curl_init();
curl_setopt($curl_handle, CURLOPT_URL, 'https://www.habbo.nl/api/public/users?name='.$r->habboname);
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_USERAGENT, 'myproject');
$query = curl_exec($curl_handle);
curl_close($curl_handle);

echo 'Query: '.$query;
$json = json_decode($query, true);
echo '<pre>' . print_r($json, true) . '</pre>';

echo get_remote_data('https://www.habbo.nl/api/public/users?name='.$r->habboname, true );
file_get_contents(filename)
?>

1 个答案:

答案 0 :(得分:1)

我得到了答案:

$ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, 'http://www.habbo.nl/api/public/users?name='.$r->habboname);
        curl_setopt($ch, CURLOPT_USERAGENT, 'github.com/gerbenjacobs/habbo-api v2.2.0');
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        // urls at /extradata/ require javascript/cookie validation, trick them.
        $data = curl_exec($ch);
        $info = curl_getinfo($ch);
        curl_close($ch);

        $json=json_decode($data, true);
        echo $json['figureString'];