Third-Party Login summary

Source: Internet
Author: User

Description

Because of the business needs, so the two days to take a look at the third-party login API, so that the third-party login.

First, apply for AppID

To QQ and Sina Weibo development platform application AppID and secret, this is a Baidu Apistore, third-party login;

Second, QQ login

1. Using JS

I. First introduce JS (Redirecturi is the return page address after successful login)

<script type = "Text/javascript" src="http://qzonestyle.gtimg.cn/qzone/openapi/qc_loader.js" Data-appid="appid" data-redirecturi=" Redirecturi " charset=" utf-8 "></script >

Ii. Bind login button (only one element ID is required, the default button is automatically generated)

QC. Login ({

Btnid:Node ID for"qqloginbtn" //Insert button

});

2. Using OAuth (authorization mechanism)

I. Using a custom button

<a href= "Javascript:qqlogin (); ></a>

Use QQ login function Qqlogin () {location.href = ' https://graph.qq.com/oauth2.0/authorize?client_id= ' +thirdlogin.appid_   qq+ ' &response_type=token&scope=get_user_info&redirect_uri= ' +getcurrlocation (); }//Get the current page path--from which page login, login successful, return which page function getcurrlocation () {return window.location.protocol + '//' +window.locatio  N.host + window.location.pathname; }

II. After successful login, get OpenID and Access_token

Check the QQ login status function check_qq_login_status () {//Check whether the login succeeded if (QC. Login.check ()) {//Login successful, get OpenID QC.               Login.getme (function (openid,accesstoken) {var data = ' openid= ' +openid;            Callback (1,data);         }); }   }

Third, micro-blog Login

1. Using JS

I. Introduction of JS

<script src= "Http://tjs.sjs.sinajs.cn/open/api/js/wb.js?appkey=YOUR appkey" type= "Text/javascript" charset= " Utf-8 "></script>

II. BIND Login button

Html<div id= "Wb_connect_btn" ></div>//jswb2.anywhere (function  (W)  {     w.widget.connectbutton ({        id:  "Wb_connect_btn",         type:  ' 3,2 ',         callback: {            login:  function  (o)  { //callback function after login                  alert ("login: "  + o.screen_name)              },             logout: function  ()  { //callback function after exiting                  alert (' logout ');             }&nbs(P;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;}&NBSP;&NBSP;&NBSP;&NBSP;});}); 

2. Using OAuth

I. Custom button

<a href= "Javascript:wblogin (); ></a>

Use Weibo login function Wblogin () {location.href = ' https://api.weibo.com/oauth2/authorize?client_id= ' +thirdlogin.appid_w   B + ' &client_secrect= ' +thirdlogin.secret_wb+ ' &response_type=code&redirect_uri= ' +getCurrLocation (); }

After successful login, will jump to redirect_uri?code=**** (with the code parameter, code is not bound to the user, can not be used to identify the user)

II. Get Access_token

Using this interface (code is returned by the above interface), you can get to Access_token, which is the interface need to request the way it is post

https://api.weibo.com/oauth2/access_token?client_id=your_client_id&client_secret=your_client_secret& Grant_type=authorization_code&redirect_uri=your_registered_redirect_uri&code=code

My idea is that after the use of the previous interface authorization succeeds, in the return page according to code, and then asynchronously request the background, the background call this interface, and then return the JSON data (the returned data has Access_token and UID);

Iv. withdrawal

1. QQ exit

Qc. Login.signout ();

2. Weibo exit

Just using the Wb2.logout () method does not necessarily really exit (because it is executed asynchronously, you can try).

My workaround, depending on the login status to determine whether to exit, do not exit to continue execution

Timeid = SetInterval ("Wb_logout ()", 50);        Use Timer//exit microblog function Wb_logout () {if (Wb2.checklogin ()) {wb2.logout ();            }else{clearinterval (Timeid);  Location.href = Getcurrlocation (); After exiting, refresh the page (in order to change the display status of user information)}}

V. Summary

Because the time is tight, also did not look closely, but the display is completely can realize login, exits.

Third-Party Login summary

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.