Brief Introduction to the development process of the "Log on with Sina Weibo account" Function

Source: Internet
Author: User

Many websites use the third-party account login function (which is basically implemented through OAuth 2.0). If your website or project needs to implement such a function, it is actually very easy. The following describes the open APIs provided by Sina Weibo.

1. Apply for an appkey and appsecret on the Weibo open platform, and fill in various materials

2. Program Development

The Sina Weibo open platform provides sdks for download, and we can use the ready-made Sina Weibo OAuth certification class in it, which is named SaeTOAuthV2.

I provide a ready-made file for download, which not only includes the SaeTOAuthV2 class, but also encapsulates the SaeTClientV2 class for various Sina Weibo interfaces. In fact, we don't need it, or we can build our own classes based on the APIS it provides. (I am using the php language)

1) the first step of Sina Weibo OAuth authentication process is to direct the user to the Sina Weibo OAuth authentication page, so we need to get the url of this page.

Let's talk about $ callback_url, which means that after Sina authentication, the url page you specified will jump to. On this page, you can process the authentication result. In addition, we generally perform authentication in code mode, that is, the second parameter of the getAuthorizeURL function. For other authentication methods, refer to Sina's documentation.

2) The second step is to process the authentication result on the callback page $ callback_url.

After you log on to and authorize the Sina Weibo OAuth page, you will be redirected to the specified $ callback_url page. In addition, the url of this page contains a code parameter, this parameter is provided by sina. We use the value of this code parameter to obtain the access_token.

Note that the $ token we get is an array, and $ token ['Access _ token'] is the real access_token token. We can store it in sessions for future calls.

3) Step 3, with the access_token token, we can access various api interfaces provided by Sina Weibo.

For more information about the APIs and Their returned results, see the Sina api documentation. json data is returned.

After obtaining the access_token, it indicates that we can use the api to obtain information about the Sina Weibo user. With this information, we can develop the login function, such as binding an account.

 

Well, it's that simple. It's easy to understand the process.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.