Facebook Graph API integration built on Val Town.
Go to developers.facebook.com/apps and create a new app. Note the App ID and App Secret from App Settings ā Basic.
| Key | Description |
|---|---|
FB_APP_ID | Your Meta App ID |
FB_APP_SECRET | Your Meta App Secret |
FB_PAGE_ACCESS_TOKEN | Page Access Token (from Graph API Explorer or Page settings) |
FB_VERIFY_TOKEN | Any random string you choose (used for webhook verification) |
š Add FB_APP_ID here: https://www.val.town/x/ziadamrme/Facebook_mcb/environment-variables?key=FB_APP_ID
š Add FB_APP_SECRET here: https://www.val.town/x/ziadamrme/Facebook_mcb/environment-variables?key=FB_APP_SECRET
š Add FB_PAGE_ACCESS_TOKEN here: https://www.val.town/x/ziadamrme/Facebook_mcb/environment-variables?key=FB_PAGE_ACCESS_TOKEN
š Add FB_VERIFY_TOKEN here: https://www.val.town/x/ziadamrme/Facebook_mcb/environment-variables?key=FB_VERIFY_TOKEN
In your Meta App dashboard, go to Webhooks, add the live endpoint URL above as the callback URL, and use the same FB_VERIFY_TOKEN you set as the env var.
| Function | Description |
|---|---|
graphGet(path, params) | Generic Graph API GET request |
graphPost(path, body) | Generic Graph API POST request |
postToPage(pageId, message) | Post a text message to a Page's feed |
postLinkToPage(pageId, link, message?) | Post a link (with optional message) to a Page's feed |
getPageInfo(pageId) | Get Page info (name, fans, about, etc.) |
getPagePosts(pageId, limit?) | Get recent posts from a Page |
getLongLivedToken(appId, appSecret, shortToken) | Exchange a short-lived token for a long-lived one |
main.ts ā HTTP endpoint (webhook verification + event receiver)
lib/facebook.ts ā Graph API helper functions