tomek550
tomek550

Reputation: 470

Public facebook page feed

I want to add last 4 news to my website, fetching them from facebook API. There is no facebook login on website or anything like that. I've created FB APP and used FB.api() function to fetch news, but APIs need access_token, which should not be seen publicly, but news fetching is on frontend (js). Is there a way to obtain some other access_token only for reading public news which can be public?

My code (which is working, just not safe)

    window.fbAsyncInit = function() {
        FB.init({
            appId      : 'my_app_id',
            xfbml      : true,
            version    : 'v2.8'
        });
        FB.api(
            "https://graph.facebook.com/my_fb_page/feed?fields=full_picture,message,story,created_time&access_token=my_access_token",
            function (response) {
                if (response && !response.error) {
                    var news = response.data.splice(0,4);
                    console.log(news);
                }
            }
        );
    };

Upvotes: 0

Views: 299

Answers (1)

andyrandy
andyrandy

Reputation: 74014

The proper way to do this is to use the Access Token server-side. Never use Tokens on the client, the App Access Token includes the App Secret - which is called "Secret" for a reason.

More information about Tokens:

Upvotes: 1

Related Questions