Home >Backend Development >PHP Tutorial >Usage example of php Sina Weibo login interface, php Sina_PHP tutorial

Usage example of php Sina Weibo login interface, php Sina_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:10:591108browse

php Sina Weibo login interface usage example, php Sina

The example in this article describes the usage of php Sina Weibo login interface. Share it with everyone for your reference. The specific analysis is as follows:

Before logging in to Weibo, you need to apply for APP KEY and App Secret. To apply for this, please go to open.weibo.com to apply for related content.

There are also related development documents on the official website http://open.weibo.com/wiki/. You can view relevant information. The php SDK I downloaded here can be used directly for web website applications.

Download the SDK and configure the config file. The code is as follows:

Copy code The code is as follows:
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 will jump to YOUR_REGISTERED_REDIRECT_URI/?code=CODE //YOUR_REGISTERED_REDIRECT_URI is your callback address. */
//Then the first step is to guide the user to authorize.

include_once( 'config.php' );
include_once( 'saetv2.ex.class.php' );
$o = new SaeTOAuth( WB_AKEY , WB_SKEY );
$code_url = $o->getAuthorizeURL( CANVAS_PAGE );
echo "Authorization";
//The authorization address is:
https://api.weibo.com/oauth2/authorize?client_id=YOUR_CLIENT_ID&response_type=code&redirect_uri=YOUR_REGISTERED_REDIRECT_URI
?>


If the user agrees to the authorization, you need to obtain the Access Token in your callback address to call the interface and obtain the information. The code is as follows:
Copy code The code is 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 obtaining the AccessToken, you can call all the encapsulated functions of saetv2.ex.class.php to perform operations. For example, when I do the login function here, I need to obtain the user’s information. The code is as follows:
Copy code The code is as follows:
/**
* Get user information based on user UID or nickname
*
* Return user information by user UID or nickname, and also return the user's latest Weibo.
*
Corresponding 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 be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/932073.htmlTechArticlephp Sina Weibo login interface usage example, php Sina This article describes the php Sina Weibo login interface usage example. Share it with everyone for your reference. The specific analysis is as follows: Login to Weibo...
Statement:
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