javascript - Facebook Graph API console error -


i trying display feed console using console.log returning error of no token.

message: "an active access token must used query information current user." type: "oauthexception" error code : 2500;

the message above getting. have followed steps given fb.

the code bellow.

<script>   window.fbasyncinit = function() {     fb.init({       appid      : '',       xfbml      : true,       version    : 'v2.1',      });     fb.api('/me', {fields: 'last_name'}, function(response) {     console.log(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 = "http://connect.facebook.net/en_uk/sdk.js";      fjs.parentnode.insertbefore(js, fjs);    }(document, 'script', 'facebook-jssdk'));      </script> <div id="fb-root"> </div> 

you trying call api without asking user login first. instead, remove fb.api line in code , replace below:

fb.login(function(){   fb.api('/me', 'get', {fields: 'last_name'}, function (response ) {     console.log(response);   }); }); 

ideally, should call above login code when "login" button pressed, e.g.:

<button type="button" onclick="dologin();">login facebook</button> 

(remember wrap fb.login() function in dologin() function.)


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -