Php Sina Weibo logon interface usage instance, php Sina. Php Sina Weibo logon interface usage example. php Sina this article describes the php Sina Weibo logon interface usage. Share it with you for your reference. The specific analysis is as follows: an example of using the Sina Weibo login interface to log on to php via Weibo, php Sina
This example describes the usage of the php Sina Weibo logon interface. Share it with you for your reference. The specific analysis is as follows:
Before logging on to Weibo, you need to apply for the app key and App Secret. to apply for this method, go to open.weibo.com to apply for relevant content.
Relevant development documents are also available on the official website: http://open.weibo.com/wiki/you can refer to the relevant information. I will download PHP sdkto directly go to the Web site application.
Download the SDK and configure the config file. the code is as follows:
The code is as follows:
<? Php
Header ('content-Type: text/html; charset = UTF-8 ');
Define ("WB_AKEY", 'xxxxxxxxxxxx ');
Define ("WB_SKEY", 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ');
Define ("WB_CALLBACK_URL", 'http: // xxxxxxxxxxxx/callback. php'); // callback address
/* The callback address here refers to the page jump to YOUR_REGISTERED_REDIRECT_URI /? Code = CODE // YOUR_REGISTERED_REDIRECT_URI is your callback address. */
// 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 "authorize ";
// 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 information, the code is as follows:
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 obtaining the AccessToken, you can call all encapsulated functions of saetv2.ex. class. php to perform operations. for example, you need to obtain the user information by using the login function. the code is as follows:
The code is as follows:
/**
* Obtain user information based on user UID or nickname
*
* Return user information by user UID or nickname, and return the user's latest Weibo posts.
*
Corresponding API: users/show
*
* @ Access public
* @ Param mixed $ uid_or_name 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 php programming.
The example in this article describes the usage of the php Sina Weibo logon interface. Share it with you for your reference. The specific analysis is as follows: log on to Weibo...