GitHub - leftmove/facebook.js: A Facebook API wrapper that's not from 2011.

3 min read Original article ↗

Important

This library is in active development.

[ the bookface ]

Bookface is a modern TypeScript wrapper for Meta's developer services.

The Graph API is Meta's platform for building apps and services that interact with their products (i.e. Facebook, Instagram).

Bookface allows you to interact with the Graph API through TypeScript with a more intuitive, organized, and straightforward syntax.

Getting Started

To get started with Bookface, you'll first need to install it through your preferred package manager. See the extended install section for this.

Once installed, in order to do anything useful, you'll need to create an app with Meta in their developer portal and then authenticate said app with Bookface's CLI. This can be complicated, and the process is heavily dependent on what you're trying to do, so it's recommended you go through the in-depth, step-by-step authentication guide provided on the documentation site.

Once you've done all the necessary steps required to interact with Meta's API programmatically, you can finally get started with some actual code. The following is a minimal example for publishing and reading page posts.

import Facebook from "bookface";
import type { Authentication } from "bookface";

// Initialize the client
const facebook = new Facebook();
const auth: Authentication = {};

// Login (unnecessary but good to have)
await facebook.login(auth).then(({ credentials, scope }) => {
  console.log(credentials);
  console.log(scope);
});

// Publish a post to your page
const post = await facebook.page.posts.publish({
  message: "Hello World!",
  media: "./image.png",
});

// Read your page posts
const posts = await facebook.page.posts.read();

To do anything else with Bookface, or for a more thorough understanding of the syntax, it's highly recommended that you check out the documentation site.

Install

JSR

NPM Version

bunx jsr add @bookface/ts # Bun

npx jsr add @bookface/ts # npm

deno add jsr:@bookface/ts # Deno

pnpm i jsr:@bookface/ts # pnpm 10.8 or older
pnpm dlx jsr add @bookface/ts # pnpm

yarn add jsr:@bookface/ts # Yarn 4.8 or older
yarn dlx jsr add @bookface/ts # Yarn

If you want to install from npm, rather than using jsr, you can use the @anonyo/bookface package instead. It should be noted though that this package is not as well maintained as the jsr package.

Once you've installed, you'll likely want to login. You can do this with following command. Replace npx with your preferred package manager's package runner (i.e. bunx, dlx).

Contributing

This project is looking for contributors — feel free to submit a pull request or open an issue.

If you're looking for something to work on, check out the roadmap for direction.

License

MIT