To obtain Sina weibo data, you can use the API address: open. weibo. comwikiAPI doc_v2. The data can be obtained as follows: 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 the header information. 0 indicates that the header information is not displayed. 1 indicates that the default value is 0.
// Curl_setopt ($ curl, CURLOPT_HEADER, 0 );
// Set the cURL parameter to save the result to the string or output to the screen. 0 is displayed on the screen, and 1 is not displayed on the screen. the default value is 0.
Curl_setopt ($ curl, CURLOPT_SSL_VERIFYPEER, false );
Curl_setopt ($ curl, CURLOPT_RETURNTRANSFER, 1 );
// The 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'
';
print_r($result);
echo '
';
}
?>
In addition, json_decode ($ data) will output an object, while json_decode ($ data, true) will force the output as an array. The CURL library is used to obtain the array.
PHP CodeBase Code Library Plan. generally, one function is collected at a time to solve a problem.