I need to show the newest 5 posts from my facebook application, and I need to avoid running any server-side code. The following worked until this morning:
var id = myappid;
var limit = 5;
var div = document.getElementById('facebook_posts');
FB.init();
FB.api('/'+id+'/posts', {'limit': limit}, function(response) {
if (response && response.data && response.data.length) {
div.innerHTML = '';
for (var i=0, l=response.data.length; i<l; i++) {
var post = response.data[i];
if (post.message && post.link)
div.innerHTML += '<a href="' + post.link + '">' + post.message + '</a><br/>';
}
} else {
div.innerHTML = 'Error loading facebook posts';
}
});
I didn’t change anything, but now facebook returns an “OAuthException” with the message “An access token is required to request this resource.”. The API says I need “Any valid access_token to see public”. So, how do I get “Any valid access_token” without showing an authendication pop-up?
The easiest thing would be to use an offline access token created for your administrator user. Look here to find out how to create one.