This article describes the PHP Sina Weibo login interface usage. Share to everyone for your reference. The specific analysis is as follows:
Before doing microblogging landing is required to apply to the app KEY and app Secret, this application method please go to open.weibo.com application related content.
In the official website also has the related development document http://open.weibo.com/wiki/may view the related information, I here downloads the PHP SDK directly to carry on the Web site application.
Download the SDK, configure the config file, the code is as follows:
Copy Code code as follows:
<?php
Header (' content-type:text/html; Charset=utf-8 ');
Define ("Wb_akey", ' xxxxxxxxxx ');
Define ("Wb_skey", ' xxxxxxxxxxxxxxxxxxxxxxxxx ');
Define ("Wb_callback_url", ' http://xxxxxxxxxxxx/callback.php ');/callback Address
/* The callback address here means that if the user agrees to authorize, the page jumps to Your_registered_redirect_uri/?code=code//your_registered_redirect_uri is your callback address. */
That's the first step. You need to first direct the user to authorization.
Include_once (' config.php ');
Include_once (' saetv2.ex.class.php ');
$o = new Saetoauth (Wb_akey, Wb_skey);
$code _url = $o->getauthorizeurl (canvas_page);
echo "<a href= $code _url> authorization </a>";
The authorized address is:
Https://api.weibo.com/oauth2/authorize?client_id=YOUR_CLIENT_ID&response_type=code&redirect_uri=YOUR_ Registered_redirect_uri</pre>
?>
If the user agrees to authorization, in your callback address you will need to get access Token to call the interface, get the information, the code is as follows:
Copy Code code as follows:
if ($_request[' code ']) {
echo "SDS";
$keys = Array ();
$keys [' code '] = $_request[' code '];
$keys [' redirect_uri '] = canvas_page;
$tt = new Saetoauth (Wb_akey, Wb_skey);
$BB = $tt->getaccesstoken (' Code ', $keys);
Var_dump ($BB);
}
After successfully acquiring the Accesstoken, you can invoke all the encapsulated functions of saetv2.ex.class.php, for example, I need to get the user's information for the login function here, the code is as follows:
Copy Code code as follows:
/**
* Obtain user information based on user UID or nickname
*
* Return user information by user UID or nickname, and will return to the user's newly released microblog.
* <br/> corresponds to Api:users/show
*
* @access Public
* @param mixed $uid _or_name user uid or Weibo nickname.
* @return Array
*/
function Show_user ($uid _or_name)
{
return $this->request_with_uid (' Https://api.t.sina.com.cn/users/show.json ', $uid _or_name);
}
I hope this article will help you with your PHP program design.