This is a set of tools that help you manage Facebook advertisements
It is used to monitor the Facebook spending and send notification to given receivers
usage: fb_monitor_cost.py [-h] [-c CONFIG] (-m | -a) [-t THRESHOLD]
Facebook Spending Monitor
optional arguments:
-h, --help show this help message and exit
-c CONFIG, --config CONFIG
The absoluate path to configuration file.
-m, --monitor Monitor facebook spending and send message to
reveicers
-a, --alarm Monitor facebook spending and notify receivers only
when the spending is above the threshold
-t THRESHOLD, --threshold THRESHOLD
Specify the threshold that 'alarm' mode will check.
You can also setup a crontab to monitor the facebook spending.
# crontab rule: check facebook spending every hour
0 * * * * python3 /path/to/fb_monitor_cost.py -c /path/to/facebookads.cfg -m
It is used to export the facebook targeting spec and query the esstimate advertisement costs. It can output tab-separated file.
usage: fb_targetspec.py [-h] [-c CONFIG] {query,import} ...
Facebook Targetting Spec Tool
positional arguments:
{query,import} Supported commands
query Query and output the specified countries' spec and
reach estimate data.
import Import the targeting_spec generated by 'query' command
and created audience groups
optional arguments:
-h, --help show this help message and exit
-c CONFIG, --config CONFIG
The absoluate path to configuration file.
It supports two commands: query and import
For the query command:
usage: fb_targetspec.py query [-h] [-f FILE] [-ct COUNTRY] [-ef]
[--age-min AGE_MIN] [--age-max AGE_MAX]
[--age-step AGE_STEP]
optional arguments:
-h, --help show this help message and exit
-f FILE, --file FILE The tab separated file that will be exported
-ct COUNTRY, --country COUNTRY
The country code for example JP for Japan.
-ef, --exclude-female
All females will be exluded by default
--age-min AGE_MIN The minimal age
--age-max AGE_MAX The maximum age
--age-step AGE_STEP The step between age_min and age_max
For Ubuntu 14.04, you have to update the pip
wget https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py
Then install the dependencies
pip3 install facebookads
pip3 install facepy
You can refer to this article: Obtaining Never-expiring Access_token to Post on Facebook Page
- Open Facebook API Explorer
- Select the given application
- Select the proper permissions (ads_management, ads_read, read_insights etc)
- Press the button 'Get Access Token'
Construct a CURL request like that
curl -d "https://graph.facebook.com/oauth/access_token?client_id=<my_app_id>&client_secret=<my_app_secret>&grant_type=fb_exchange_token&fb_exchange_token=<short-lived-access_token>"
The 'curl' response will include the new long-lived (60 days) access token and its expiration date.
Go to Facebook Explorer Tool
Send requests to /v2.0/me/accounts. In the response JSON, you will find a access_token. Please copy it.
Go to Facebook AccessToken Tool
Submit your copied access token, you will see Expires:Never in the response.
Make a configuration file
[Authentication]
app_id = <facebook app id>
app_secret = <facebook app secret>
access_token = <facebook access token>
[Defaults]
ad_account = <facebook ads account id>
[Email]
# Note: SMTP SHOULD SUPPORT SSL
email_sender = <sender@mail.com>
# You can specify multi receivers by ','
# For example:
# email_receiver = user1@mail.com,user2@mail.com
email_receiver = <receiver@mail.com>
email_smtpserver = <smtp.mail.com>
email_username = <sender@mail.com>
email_password = <password>
email_port = <port>
[JSONStore]
# Use JSON to store data