Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
54
rated 0 times [  55] [ 1]  / answers: 1 / hits: 32962  / 10 Years ago, mon, november 3, 2014, 12:00:00

I'm trying to output my Facebook feed to a div element.



Using this code:



<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'APP ID HERE',
xfbml : true,
version : 'v2.1'
});

FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
console.log('Logged in.');
}
else {
console.log('initiate FB login...');
FB.login();
}
});


FB.api('/me/feed',function(response){
var idDiv=document.getElementById('result');
idDiv.textContent=JSON.stringify(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;
console.log(js.length);
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));


</script>
<div id='result'></div>


I get logged in displayed on the console, so I know that FB.getLoginStatus() has returned connected.



The div element gets populated with the following error:



{error:{message:An active access token must be used to query information
about the current user.,type:OAuthException,code:2500}}


If FB.getLoginStatus() returned connected, shouldn't there be an active access token?


More From » facebook

 Answers
20

You probably don't have the access token at the time the request to 'me/feed' is sent.



getLoginStatus does not only check if the user is authorized, it also refreshes the user session. that´s why it is important to do api calls after it is connected.



Try putting the call to FB.api inside getLoginStatus.



This question is similar to the problem you're having:Facebook javascript sdk An active access token must be used to query information about the current user


[#68935] Thursday, October 30, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
minab

Total Points: 701
Total Questions: 104
Total Answers: 91

Location: Saint Pierre and Miquelon
Member since Fri, Jan 28, 2022
2 Years ago
;