javascript - How to make Login using facebook to trigger manually -


here login using facebook. took example official docs.

here facebook login checked automatically whenever page loaded. want check on button click.

so , created div id

and had 1

<div id="fblogin">click me</div>

which triggers

$("#fblogin").click(function() {         console.log('fb initiated');         statuschangecallback(response); }); 

here don't know value response call getting error uncaught referenceerror: response not defined

short : want trigger if click on button not automatically.

here code have far

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.js"> </script> <div id="fblogin">   click me</div> <script> $("#fblogin").click(function() {         console.log('fb initiated');         statuschangecallback(response);  }); </script> <script>   function statuschangecallback(response) {     console.log('statuschangecallback');     console.log(response);     if (response.status === 'connected') {       testapi();     } else if (response.status === 'not_authorized') {       document.getelementbyid('status').innerhtml = 'please log ' +         'into app.';     } else {       document.getelementbyid('status').innerhtml = 'please log ' +         'into facebook.';     }   }   function checkloginstate() {     fb.getloginstatus(function(response) {       statuschangecallback(response);     });   }   window.fbasyncinit = function() {   fb.init({     appid      : 'myappid',     cookie     : true,      xfbml      : true,      version    : 'v2.2'   });    fb.getloginstatus(function(response) {     statuschangecallback(response);   });   };   (function(d, s, id) {     var js, fjs = d.getelementsbytagname(s)[0];     if (d.getelementbyid(id)) return;     js = d.createelement(s); js.id = id;     js.src = "//connect.facebook.net/en_us/sdk.js";     fjs.parentnode.insertbefore(js, fjs);   }(document, 'script', 'facebook-jssdk'));   function testapi() {     console.log('welcome!  fetching information.... ');     fb.api('/me', function(response) {       console.log('successful login for: ' + response.name);       document.getelementbyid('status').innerhtml =         'thanks logging in, ' + response.name + '!';     });   } </script> <fb:login-button scope="public_profile,email" onlogin="checkloginstate();"> </fb:login-button> <div id="status"> </div> 

what mistake doing , how can fix ?

remove/comment call fb.getloginstatus() in window.fbasyncinit. change button's click event handler code :

$("#fblogin").click(function() {     console.log('fb initiated');     checkloginstate();  }); 

response passed callback function fb.getloginstatus, requests , returns in response login status of user.


Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -