Http://www.cnblogs.com/e241138/archive/2013/03/15/sina-weibo-oauth-access_token.html
Sina Weibo oauth2.0 authorizes access token
The Sina Weibo open platform provides a wide range of API interfaces that allow developers to develop unique Weibo applications. However, most interfaces require the user to authorize the application. The application uses the authorized access token to call the corresponding interface to obtain the content.
Sina Weibo's authorization mechanism currently has three main application scenarios:
- Web Applications
- Mobile applications
- Intra-site applications
The Sina Weibo development documentation is here
Here is the API documentation for Sina Weibo
In my personal understanding, the so-called API interface is that each function corresponds to a URL, submit corresponding parameters, and then return results.
Example
Oau22/authorize
Oau2's authorize Interface
URL
Https://api.weibo.com/oauth2/authorize
This URL is the interface, and the corresponding parameters submitted for this interface are called accordingly.
This document describes how to authorize and obtain access tokens for Web applications.
Step 1: Add a website
Go to the Sina Weibo open platform, go to "Management Center", click "create application", select "Web application", fill in the corresponding information, and submit.
Step 2: Configure oauth2.0 authorization
After the application is created, you can view the information in "Management Center"-"My applications, in "application information"> "advanced information", you can set the website authorization callback page and the canceling authorization callback page.
The authorization callback page is very important and must be filled in correctly. After the user's authorization is successful, the page will be called back and a "code" parameter will be returned. developers can exchange the code for the access token value.
Step 3: Guide user authorization
Guide authorized users to the following page:
Https://api.weibo.com/oauth2/authorize? Client_id =Your_client_id& Response_type = Code & redirect_uri =Your_registered_redirect_uri
Your_client_id: The appkey of the application, which can be viewed in the basic information of the application.
Your_registered_redirect_uri: The authorization callback page that you entered earlier. Be sure to make sure it is the same.
After successful authorization, the user will jump to the callback page. The developer needs to get the code value in the URL parameter at this time. Note that the code can only be used once.
Step 4: Exchange access token
Developers can access the following page to get the access token:
Https://api.weibo.com/oauth2/access_token? Client_id =Your_client_id& Client_secret =Your_client_secret& Amp; grant_type = authorization_code & redirect_uri =Your_registered_redirect_uri& Code =Code
These parameters are not described in detail.
If no problem exists, you can get the access token. Return example:
{ "access_token": "ACCESS_TOKEN", "expires_in": 1234, "remind_in":"798114", "uid":"12341234" }
Step 5: Call an API
After obtaining the access token, the developer can save its value and use it directly when calling the API. The access token has a certain validity period and needs to be re-authorized after expiration.