3. Access Token and User Id¶
If we want to automatize our Facebook Marketing API data collections, we need two important information:
A User Id: any FB user automatically has a user ID, we just need to find it.
An access token: that is not so simple to get, but any FB user can obtain one free of charge. First, you will need to create a developer account, create a dummy app and an access token for this app.
The following sections will show step-by-step how to obtain these two identifiers.
3.1. User ID¶
Your User ID can be obtained by the URL used to access the Marketing API Web Interface, for that:
Log into your Facebook Account: facebook.com
Copy and paste in your browser the following URL: https://www.facebook.com/adsmanager/creation.
You do not need to accept any pop-up or anything, just note that the URL has automatically changed and now shows your user Id just after the keyword act_. For example, from the URL https://www.facebook.com/ads/manager/creation/creation/?act=1234567890&filter=blablabla…, your userID would be 1234567890.My own user Id is shown below: 326899….:
Store your user Id somewhere safely.
3.2. Access Token¶
The list of steps below will help you create a valid FB token that can be used by pySocialWatcher:
You will need to have a developer account. For that, go to https://developers.facebook.com and link your regular FB account to the developer one.
FB will require you to validate your account by either asking you for your mobile phone number or valid credit card number. If your phone number was already previously provided to FB, then there is nothing to be done in this step.
Create a dummy app. The name does not matter and the default name is fine.
Once you have created your app, add a marketing API tool:
After configuring the Marketing API (just accept the default options), it will be displayed in the main dashboard of your app as follows:
In the Marketing API dropdown list, click on Tools and generate a token with ads_management and ads_read and manage_page.
Click on get token and save the generated token.
To get information about your token and check its expiring date, you can take advantage of the following URL by appending your token at the end of it: https://developers.facebook.com/tools/debug/accesstoken/?access_token=<YOUR_TOKEN>