Performing actions on behalf of a Facebook page requires access to the page's access token. Here's a step-by-step guide to obtaining your Facebook page's access token using the Graph API Explorer:
- Navigate to the Graph API Explorer.
- From the dropdown menu, select your desired app.
- Click "Get Access Token" and then select the
manage_pages
permission. (Note: You might also need theuser_events
permission.) - Access the
me/accounts
connection and copy your page'saccess_token
. - Click on your page's ID.
- Add the page's
access_token
to the GET fields. - Call the desired connection (e.g.,
PAGE_ID/events
).
Note: If you wish to grant permanent access to a page, allowing the Facebook App to access the page even when you're logged out, refer to the documentation at http://developers.facebook.com/docs/opengraph/using-app-tokens/. An App Access Token does not expire unless the application secret is refreshed through app settings.
For more information, consult the Facebook Graph API documentation on Page Tokens.
If you're using Node.js with the fbgraph library, you can retrieve the page access token with the following code:
var facebookAccountID = yourAccountIdHere
graph
.setOptions(options)
.get(facebookAccountId + "/accounts", function(err, res) {
console.log(res);
});
The token you need can be found at res.data[0].access_token
in the JSON response.
Troubleshooting:
If you encounter difficulties in obtaining the Page access token, ensure that you are an administrator of the page and that the app has access to the page. If you're still facing issues, refer to the official documentation or seek assistance from the Facebook developer community.