PHP Get Sina Weibo Data API Example_PHP Tutorial

WBOY
Release: 2016-07-13 10:25:15
Original
806 people have browsed it

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.'
';

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
//Set whether to display header information. 0 is not displayed, 1 is displayed. The default is 0
//curl_setopt($curl, CURLOPT_HEADER, 0);
//Set cURL parameters, requiring the results to be saved in a string or output to the screen. 0 is displayed on the screen, 1 is not displayed on the screen, the default is 0
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
// To be verified Username and password
curl_setopt($curl, CURLOPT_USERPWD, "username:password");
$data = curl_exec($curl);
curl_close($curl);

$result = json_decode($data, true);

echo '

';<br> print_r($result);<br> echo '
';
}
?>
To add, json_decode($data) will output an object, while json_decode($data, true) will force the output to be an array. To obtain the array, the CURL library is used.
PHP CodeBase code base plan generally collects one function at a time to solve one problem.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/825149.htmlTechArticle?php function getWeiboData() { $count = 15; // Enter your authorization number after the parameter source $url = "https://api.weibo.com/2/statuses/home_timeline.json?source=123456789page=1"; echo $url...
Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!