Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
316 views
in Technique[技术] by (71.8m points)

javascript - Get long term access token for Facebook page

I'm using Jquery Facebook Wall to retrieve the latest status of a Facebook page and show it in a website.

(function($) {
    $(document).ready(function(){
        $('#facebook_wall').facebook_wall({
            id: '560124337XXXXX',
            access_token: 'CXGXhXZA7Wg2XXDcTi7WmX1wp71u5fNXXa9XXX3LmXXx',
            limit: 1
        });
    });
})(jQuery);

// ...

When I use FB Graph API Explorer to get the access token of the page, I get one that expire in only 60 minutes. Is there a way to get a long duration access token? Or to generate a new one each time a user connect to the website page?

PHP is not allowed since the website isn't hosted in an Apache server. I'm seeking a client-side solution. Any help will be highly appreciated.

Update : According to my researches, I assume that getting a token that doesn't expire in one month and that have Manage Pages permission (the only permission that grant reading a page feeds), require the creation of a Facebook app that include "Facebook login" and then waiting for the "Review Process" approval.

I don't have any intention to make people login since it's a static website. Is there a possibility to get a static access token that doesn't expire in an hour and that have the permission of "reading page's feed", without creating the app, adding a privacy policy page URL for it, waiting for the review process, making people login... And without resorting to server-side options?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

How to generate different Tokens (App Token, User Token, Page Token, Extended User Token, Extended Page Token) is explained very well in the docs:

Here′s another link if that is not enough:

As CBroe commented, you don′t need extended Tokens client-side. For getting the feed of a Page, an App Token is good enough - but you should NEVER expose your App Secret on the client. It is called Secret for a reason. And i hope you′re not trying to use static Token like that for every user. Whatever Token you are using, don′t expose it to any other users.

You could also just use the Page Plugin: https://developers.facebook.com/docs/plugins/page-plugin (again, thanx to CBroe for pointing out that additional solution).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...