Web Access QQ Login two ways _javascript skills

Source: Internet
Author: User
Tags openid

First to introduce the authorization JS file

<script type= "Text/javascript" src= "Http://qzonestyle.gtimg.cn/qzone/openapi/qc_loader.js" 101140406 "data-redirecturi=" http://127.0.0.1 "charset=" Utf-8 "></script>

Then access QQ Login

The first is to use the system's own button to log in, but this will pop up a new window, do not like//Call the Qc.login method, specify the Btnid parameter to bind the button in the container node QC. Login ({//btnid: Node ID for Insert button, required Btnid: "QQLOGINBTN",//user needs to confirm scope authorization, optional, default all scope: "All",//button size, available values [a_xl| a_l| a_m| a_s| b_m| b_s| 
C_S], optional, default b_s size: "B_m"}, Function (Reqdata, opts) {//Login Success Console.log (Reqdata, opts); According to the returned data, the Replace button displays the state method var dom = document.getElementById (opts[' Btnid ')), _logouttemplate=[//Avatar ' <span></span> ',//nickname ' <span>{nickname}</span> ',//exit ' <span> <a href= "JAVASCRIPT:QC. 
Login.signout (); "Rel=" External nofollow "> Exit </a></span> '].join ("); Dom && (dom.innerhtml = QC. String.Format (_logouttemplate, {NICKNAME:QC). 
String.eschtml (Reqdata.nickname),//XSS Filtering Figureurl:reqData.figureurl})); 
}, function (opts) {//Logoff Success alert (' QQ login logout successful '); 

}); The second, using a custom button <a> tag link to the past, and then successfully calling this address, a tag's href can refer to the first type of window.location Qc.api ("Get_user_info", {})//Specify interface access successful receive function , s for successful return responseObject. Success (function (s) {console.log (s); A successful callback is obtained by S.data to get the Openapi return Data alert ("Get the user information successfully!") 
The current user nickname is: "+s.data.nickname"; //Specifies the receive function for interface access failure, F returns the response object for failure. Error (function (f) {//Failed callback alert ("Failed to get user information!") 
"); //Specifies the receive function after the interface completes the request, and C returns the response object for the completion request. Complete (function (c) {//Complete request callback alert ("Get user information complete!") 
"); 

}); Check if (QC) is logged in. Login.check ()) {//If the QC is logged in. Login.getme (OpenID, Accesstoken) {alert (["Current logged-on user", "OpenId is:" +openid, "Accesstoken is:" +accesstoken].join ( 
"\ n")); 
}); Here you can call your own save interface//...}

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.