Php obtains Sina Weibo Data API instance _ php instance

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.