开发者

How do I get “any valid access_token” for reading public posts?

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/&g开发者_运维知识库t;';
        }
    } 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.


You can also use the token that the Facebook graph API explorer uses. But don't grab one from your personal account if you are embedding the token in your page.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜