Js how to call qq Internet API to achieve third party login

  • 2020-03-30 02:29:17
  • OfStack

Qq connected js SDK:http://wiki.connect.qq.com/js_sdk%E4%BD%BF%E7%94%A8%E8%AF%B4%E6%98%8E
 
<script type=text/javascript> 

 On the page header The introduction of: <script type="text/javascript" 
src="http://qzonestyle.gtimg.cn/qzone/openapi/qc_loader.js" 
data-appid="appid" data-redirecturi="huidiaodizhi( with http)" 
charset="utf-8"></script> 

 in body Add the following information:  

//Set the qq share button
QC.Login( 
{ 
btnId : "qqLoginBtn" //The node id of the insert button
}, 
function(reqData, opts) {//Login successful

//Change the button to show the status method based on the returned data
var dom = document.getElementById(opts['btnId']), _logoutTemplate = [ 
// Head portrait  
'<span><img src="{figureurl}" class="{size_key}"/></span>', 
// nickname  
'<span>{nickname}</span>', 
// exit  
'<span><a href="javascript:QC.Login.signOut();"> exit </a></span>' ] 
.join(""); 
dom 
&& (dom.innerHTML = QC.String 
.format( 
_logoutTemplate, 
{ 
nickname : QC.String 
.escHTML(reqData.nickname), //Do XSS filtering
figureurl : reqData.figureurl 
})); 
}, 
function(opts) {//Cancellation of success
alert(" Log off successfully!! "); 
}); 
//Invoke API authorization
QC.api("get_info", { 
"oauth_consumer_key" : "appid" //This one doesn't have to be passed
}).success(function(s) { 
if (QC.Login.check()) {//Check for a successful login and pop up openid and accessToken
QC.Login.getMe(function(openId, accessToken) { 
alert(openid+" "+accessToken); 
}); 
} 
}); 

</script> 
<div class="lib_tiv shadow"> 
<h3 class="logo">QQ The login </h3> 
</div> 

Related articles: