Automatic post to my facebook page from Node.js se

2020-05-15 11:37发布

问题:

I have a Node.js server running a social network site and I also have a facebook page for that site. For certain actions performed by users on my site, I want to post details on the facebook page of my app.

I referred to Thuzi facebook node sdk here on how to post to facebook wall. However, it requires app id, app secret and a temporary access token. App id and app secret are constant so I can put them somewhere in my config file and use from there. But how do I get the access token without any interaction from front-end ? All posts will be published by our app only and that too on our own page. I just want this to be triggered by the end user's actions. Any help ?

I am using Sails.js framework btw.

回答1:

You would need to use an Extended Page Token for that, you only need to create it once and it will stay valid forever. And you will post "as Page" with a Page Token. How to get an Extended Page Token:

  • Create an App
  • Use the Graph API Explorer to generate a User Access Token (by authorizing the App with the manage_pages and publish_actions permission)
  • Extend the User Access Token (valid for 60 days)
  • Request an Extended Page Token by calling /me/accounts

Store that Extended Page Token on your server and use it for posting on the Page wall.

Here are some additional resources, explaining everything in detail:

  • https://developers.facebook.com/docs/facebook-login/access-tokens/
  • https://developers.facebook.com/docs/graph-api/reference/v2.1/page/feed
  • http://www.devils-heaven.com/facebook-access-tokens/
  • http://www.devils-heaven.com/extended-page-access-tokens-curl/


回答2:

I am also digging more in to this nowdays As I am working on a node module for this.

Till now I got to know that we can create a temporary access_token and we can than extend that token upto max 60 days.

For this after getting temporary token you need to make a call to this url to get a access token with 60 days validity.

https://graph.facebook.com/oauth/access_token?client_id=&client_secret=&grant_type=fb_exchange_token&fb_exchange_token=