Getting Started

Bookface is a TypeScript API wrapper for Facebook. To get started, install the package and login to your Facebook account.

Installation

Install the package using your preferred package manager.

npm install @anonyo/facebook.js
Copied

Logging In

To login to your Facebook account, use the login command.

npx facebook login
Copied

If you've never logged in before, this will prompt you for your Facebook app ID and secret.

Creating and Using an App

You can get this by visiting Meta's developer portal, and copying your credentials from App Settings > Basic.

This is what the apps page should look like.

Facebook Apps Page

If you've never created an app before, you'll need to be logged in to your Facebook developer account first before you can create an app by clicking the green button in the top right.

Otherwise, if you're already logged in, grab your credentials by following the instructions above or in your terminal.

This is what the app info page should look like.

Facebook App Settings

Basic app settings are on the left under app settings. This page has a lot of options and info, but you can safely ignore most of it for now.

Detailed instructions for creating a Meta developer account and registering an app can be found in Meta's developer documentation. It's also a good idea to read through Meta's getting started guide.

Tokens and Browser Authentication

Once you've provided your app ID and secret, the CLI app will automatically start generating your access tokens — these are your API keys, and there are three types of them (there are more, but these are the ones you'll need for now).

Since user tokens require user approval by Meta, you will have to manually approve your credentials by using a browser authentication flow.

This'll happen automatically when you use the login command and follow the steps above, but here's how that should look like.

Facebook App Settings

In order to get to this page, visit localhost:2279 (the port may be different) in your browser. This localhost link is just a redirect of the actual, longer authentication URL provided by Meta.

Once you're there, click through the flow and approve the permissions. These permissions will default to all the stuff you'll probably need when you first login, but you can change these defaults later and re-login to update them.

Tip

If you're authenticating over SSH or another remote connection, you'll have to forward the port associated with the localhost link (usually 2279) to your local machine. You can then continue as normal and visit the link printed in the console on your local machine's browser.

Finishing Up

Once you've approved your app through your browser, if everything went well, the CLI app can do the rest of the authentication for you. In the terminal you should see a success message next to all the tokens you've just generated.

Important

Take note of your credentials stored in the current directory. They're stored in in JSON format through a credentials.json file, and they contain all the sensitive tokens that allow you to control your Facebook account. Make sure to keep note of this file and take any relevant measures to secure it (i.e. add it to your .gitignore).

After this, you'll be all set to go. Take notice however of your credentials, and give them a once-over to make sure they're correct. You can do this by running the following command.

npx facebook credentials view
Copied

Your credentials are stored in the current directory, but they're also stored globally in a config directory determined by your operating system. The above command will show you both locations — take note of them. You can then use your credentials however you wish by moving around the credentials files, or by exporting the credentials by running the facebook credentials json (for JSON output) or facebook credentials shell (for shell output that exports to the environment) commands.

To continue, check out the guides page for more information on how to use Bookface.