php gets the sina weibo data API instance

  • 2020-11-20 06:02:10
  • OfStack

< ?php
function getWeiboData()
{
$count = 15;
Enter your authorization number after the source parameter
$url = "https://api.weibo.com/2/statuses/home_timeline.json?source=123456789 & count=".$count." & page=1";
echo $url.' < br / > ';

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
// Set whether to display header information 0 is not displayed, 1 is displayed as 0 by default
//curl_setopt($curl, CURLOPT_HEADER, 0);
// Set the cURL parameter to either save the result in a string or output it to the screen. 0 is displayed on the screen, 1 is not displayed on the screen, default is 0
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
// Username and password to be verified
curl_setopt($curl, CURLOPT_USERPWD, "username:password");
$data = curl_exec($curl);
curl_close($curl);

$result = json_decode($data, true);

echo ' < pre > ';
print_r($result);
echo ' < /pre > ';
}
? >
Under supplement 1, json_decode($data) outputs 1 object, while json_decode($data, true) forces the output to be an array. The CURL library is used to get the array.
PHP CodeBase code base plan, collecting 1 function at a time, solving 1 problem.

Related articles: