This article mainly introduces the usage of the php Sina Weibo login interface, analyzes the application and specific usage skills of the Sina Weibo interface in the form of examples, and has some reference value. For more information, see
This article mainly introduces the usage of the php Sina Weibo login interface, analyzes the application and specific usage skills of the Sina Weibo interface in the form of examples, and has some reference value. For more information, see
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.
You can also view related development documents on the official website. The php sdk I downloaded here is directly used for web site applications.
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.
,