Setu Recipes: reusable digital workers across every app.Browse templates

Integrations / Facebook Pages

Facebook Pages

Facebook Pages: list the Pages you manage, read posts and comments, publish posts and reply as the Page. Page actions use a Page access token.

6 actions OAuth 2 4 read2 write Calls graph.facebook.com

Connect

TypeScript
const conn = await setu.connections.initiate({ userId: "user_1", toolkit: "facebook" });
console.log(conn.connectUrl); // show this to your user
await conn.waitUntilActive();

Permissions requested

ScopeWhy it is requested
public_profileRead your name and ID so Setu can label the connection
pages_show_listList the Facebook Pages you manage
pages_read_engagementRead posts and engagement on the Pages you manage
pages_read_user_contentRead comments and posts made by visitors on your Pages
pages_manage_postsPublish posts to your Pages
pages_manage_engagementReply to comments on your Pages

Actions

Publish Page postwritefacebook.create_page_postPublish a text post (optionally with a link) on a Facebook Page, immediately. Needs the Page access token from get_page_access_token. The post goes public at once.

Needs scopes: pages_manage_posts, pages_read_engagement, pages_show_list

InputTypeDescription
page_idstringRequiredPage id
page_access_tokenstringRequiredPage access token for this Page (from get_page_access_token)
messagestringRequiredPost text
linkstringOptionalOptional URL to attach
TypeScript
await setu.execute({
  userId: "user_1",
  action: "facebook.create_page_post",
  input: {
    "page_id": "<page_id>",
    "page_access_token": "<page_access_token>",
    "message": "<message>"
  },
});
Get Page access tokenreadfacebook.get_page_access_tokenReturn each managed Page's id, name and Page access token (read via /me/accounts). Pass the token as page_access_token to the other Page actions. Treat the token as a secret and never show it to the user.

Needs scope: pages_show_list

InputTypeDescription
limitintegerOptionalMaximum Pages to return
TypeScript
await setu.execute({
  userId: "user_1",
  action: "facebook.get_page_access_token",
  input: {},
});
List Page postsreadfacebook.list_page_postsRead recent posts on a Facebook Page's feed (id, text, time, link). Needs the Page access token from get_page_access_token.

Needs scopes: pages_read_engagement, pages_read_user_content

InputTypeDescription
page_idstringRequiredPage id
page_access_tokenstringRequiredPage access token for this Page (from get_page_access_token)
limitintegerOptionalMaximum posts to return (up to 100)
TypeScript
await setu.execute({
  userId: "user_1",
  action: "facebook.list_page_posts",
  input: {
    "page_id": "<page_id>",
    "page_access_token": "<page_access_token>"
  },
});
List my Pagesreadfacebook.list_pagesList the Facebook Pages the connected person can manage, with each Page's id, name, category and their tasks. Use the id with the other Page actions.

Needs scope: pages_show_list

InputTypeDescription
limitintegerOptionalMaximum Pages to return
TypeScript
await setu.execute({
  userId: "user_1",
  action: "facebook.list_pages",
  input: {},
});
List comments on a postreadfacebook.list_post_commentsRead the top-level comments on a Page post (id, text, author, time). Needs the Page access token from get_page_access_token and a person who can moderate the Page.

Needs scopes: pages_read_engagement, pages_read_user_content

InputTypeDescription
post_idstringRequiredPost id in pageid_postid form
page_access_tokenstringRequiredPage access token for this Page (from get_page_access_token)
limitintegerOptionalMaximum comments to return
TypeScript
await setu.execute({
  userId: "user_1",
  action: "facebook.list_post_comments",
  input: {
    "post_id": "<post_id>",
    "page_access_token": "<page_access_token>"
  },
});
Reply to a commentwritefacebook.reply_to_commentPost a public reply as the Page to a comment (or a comment on a post). Needs the Page access token from get_page_access_token.

Needs scope: pages_manage_engagement

InputTypeDescription
object_idstringRequiredComment id (reply) or post id (new top-level comment)
page_access_tokenstringRequiredPage access token for this Page (from get_page_access_token)
messagestringRequiredReply text
TypeScript
await setu.execute({
  userId: "user_1",
  action: "facebook.reply_to_comment",
  input: {
    "object_id": "<object_id>",
    "page_access_token": "<page_access_token>",
    "message": "<message>"
  },
});