graph TD
root["facebook-posting/"]
root --> src["src/"]
root --> docs["docs/"]
root --> test["test/"]
root --> package_json["package.json"]
root --> env_d_ts["env.d.ts"]
root --> env_sample[".env.sample"]
root --> gitignore[".gitignore"]
src --> index["index.ts (Main Entry)"]
src --> interface["interface.ts (Types)"]
src --> token_generator["token-generator.ts (Token Runner)"]
src --> script["script/"]
docs --> feed_doc["FEED.md (Feed Tutorial)"]
docs --> msg_doc["MESSAGING.md (Messaging Tutorial)"]
script --> two_hrs["two-hour-token.ts (2-Hour Token Management)"]
script --> generator["token-generator.ts (Long-Lived Token)"]
script --> posting["posting.ts (Posting Logic)"]
script --> upload_media["upload-media.ts (Media Upload)"]
script --> messaging["messaging/ (Messaging Logic)"]
Detailed guides for each feature:
- axios:
^1.17.0- For handling HTTP requests to the Facebook Graph API. - dotenv:
^17.4.2- For managing environment variables.
- typescript:
^6.0.3 - tsx: Used for running the project directly in TypeScript.
- ts-node:
^10.9.2 - @types/node:
^25.9.3
- Copy the sample environment file:
cp .env.sample .env
- Fill in the required variables in your
.envfile:APP_ID: Your Facebook App ID.APP_SECRET: Your Facebook App Secret.SHORT_TERM_TOKEN: A short-lived user access token (see below).PAGE_ID: The ID of the Facebook Page you want to post to.FEED_TOKEN: Access token used for feed posting.MESSENGER_TOKEN: Access token used for messaging.HOSTNAME: Hostname used by the messaging module.
- Go to the Facebook Graph API Explorer.
- Select your App and the User you want to post as.
- Add the following permissions:
pages_manage_postspages_read_engagementpages_show_list
- Click Generate Token. This token usually lasts for 2 hours. Copy this to
SHORT_TERM_TOKENin your.env.
To generate a 60-day token, ensure APP_ID, APP_SECRET, and SHORT_TERM_TOKEN are set in your .env file. Then run:
npm run tokenThis script will exchange your short-lived token for a long-lived one, save it as FB_TOKEN in your .env file, and clear the value of SHORT_TERM_TOKEN.
This project includes a TwoHourToken script (src/script/two-hour-token.ts) that automatically handles fetching the correct Page Access Token from the /me/accounts endpoint using your provided credentials.
Contributions are welcome! Please see CONTRIBUTORS.md for the list of contributors and guidelines on how to take part in this project.
See CHANGELOG.md for the list of changes per version.
This project is licensed under the MIT License.