project-a / facebook-ads-performance-downloader Goto Github PK
View Code? Open in Web Editor NEWA script for downloading performance and account structure from Facebook Ads API
License: MIT License
A script for downloading performance and account structure from Facebook Ads API
License: MIT License
Currently running the downloader in a project (e.g. from a flask UI) will change the configured logger because the download()
function will change the default logging
config. IMO the logger setup should be done in the cli.py
download_data()
function.
To make it possible to see where the error message originated and to be able to configure the specific logger in the application using that library, it would be better to not use logging.xxx()
directly but declare a logger per module (or per library):
log = logging.getLogger(__name__)
...
log.warn(...)
It's also good practise to use something like this in package/__init__.py
to prevent errors when the surrounding app does not use logging
:
import logging
logging.getLogger(__name__).addHandler(logging.NullHandler())
Occasionally we get
facebookads.exceptions.FacebookRequestError:
Message: Call was not successful
Method: GET
Path: https://graph.facebook.com/v2.11/act_786040034914937/insights
Params: {'action_attribution_windows': '["28d_click"]', 'action_breakdowns': '["action_type"]', 'breakdowns': '["impression_device"]', 'level': 'ad', 'limit': 1000, 'time_range': '{"since":"2018-01-02","until":"2018-01-02"}', 'filtering': '[{"field":"ad.effective_status","operator":"IN","value":["ACTIVE","PAUSED","PENDING_REVIEW","DISAPPROVED","PREAPPROVED","PENDING_BILLING_INFO","CAMPAIGN_PAUSED","ARCHIVED","ADSET_PAUSED"]}]', 'fields': 'date_start,ad_id,impressions,actions,spend,action_values'}
Status: 500
Response:
{
"error": {
"code": 1,
"message": "An unknown error occurred",
"error_subcode": 99
}
}
This happens randomly, so adding a retry logic in this case would fix the problem
The facebook-python-ads-sdk has been renamed to facebook-python-business-sdk.
Current release of the facebook-python-business-sdk is 3.0.0.
Current release of the facebook-python-ads-sdk is 2.11.1.
Have used this very succesfully, excellent script. Currently I'm getting this:
WARNING - (#2635) You are calling a deprecated version of the Ads API. Please update to the latest version: v9.0.
How can I fix this issue?
Hi,
I tried to execute facebook-ads-performance-downloader. Getting the following error.
File "c:\python36\lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\U0001f33f' in position 56: character maps to
If possible fix the issue.
Thanks,
Hi,
Getting following error when I tried to run "facebook-ads-performance-downloder". I know this error related to facebook but we can improve the program by using asynchronously.
Response:
{
"error": {
"message": "Invalid parameter",
"type": "OAuthException",
"code": 100,
"error_subcode": 1487534,
"is_transient": false,
"error_user_title": "Too many rows",
"error_user_msg": "The reporting data you are trying to fetch has too many rows. Please use asynchronous query or restrict amount of ad IDs or time ranges to fetch the data.",
"fbtrace_id": ""
}
}
Thanks,
This is a great tool. I'd like to use it to save a backup of our daily performance, so I would put this in a daily cron job.
However, wouldn't we benefit if there was a way to save the data that would be saved if we manually went in Facebook Ads Manager and exported data to a CSV? Stuff like budget, spent, CPC, CPM would be great to save each on its own column rather that this format which is far too detailed.
Is there a way to do that?
Facebook-ads-performance-downloader stopped because Facebook API is using an updated version(5.0)
Facebook ads performance downloader downloads data from different accounts in sequence now. Making it work in parallel for different accounts will decrease the loading time very significantly (eg in our company we deal with 200 FB accounts)
The process starts by getting campaign data for my accounts and creates a temp file location and the .csv.gz. However, the shutil.py throws an error that it can't find the path. Any suggestions?
Traceback (most recent call last):
File "c:\users\myname\python\python36-32\lib\shutil.py", line 546, in move
os.rename(src, real_dst)
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:\\Users\\myname\\AppData\\Local\\Temp\\1\\tmpi4m5wlod\\facebook-account-structure_v1.csv.gz' -> '\\tmp\\facebook\\facebook-account-structure_v1.csv.gz'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\myname\Python\Python36-32\Scripts\download-facebook-performance-data-script.py", line 11, in <module>
load_entry_point('facebook-ads-performance-downloader==1.3.0', 'console_scripts', 'download-facebook-performance-data')()
File "c:\users\myname\python\python36-32\lib\site-packages\click\core.py", line 722, in __call__
return self.main(*args, **kwargs)
File "c:\users\myname\python\python36-32\lib\site-packages\click\core.py", line 697, in main
rv = self.invoke(ctx)
File "c:\users\myname\python\python36-32\lib\site-packages\click\core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "c:\users\myname\python\python36-32\lib\site-packages\click\core.py", line 535, in invoke
return callback(*args, **kwargs)
File "c:\users\myname\python\python36-32\lib\site-packages\facebook_downloader\cli.py", line 38, in download_data
downloader.download_data()
File "c:\users\myname\python\python36-32\lib\site-packages\facebook_downloader\downloader.py", line 37, in download_data
download_data_sets(ad_accounts)
File "c:\users\myname\python\python36-32\lib\site-packages\facebook_downloader\downloader.py", line 47, in download_data_sets
download_account_structure(ad_accounts)
File "c:\users\myname\python\python36-32\lib\site-packages\facebook_downloader\downloader.py", line 81, in download_account_structure
shutil.move(str(tmp_filepath), str(filepath))
File "c:\users\myname\python\python36-32\lib\shutil.py", line 560, in move
copy_function(src, real_dst)
File "c:\users\myname\python\python36-32\lib\shutil.py", line 257, in copy2
copyfile(src, dst, follow_symlinks=follow_symlinks)
File "c:\users\myname\python\python36-32\lib\shutil.py", line 120, in copyfile
with open(src, 'rb') as fsrc:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\myname\\AppData\\Local\\Temp\\1\\tmpi4m5wlod\\facebook-account-structure_v1.csv.gz'
The Facebook APIs offer a huge amount of fields and depending on the case a user may want to download more of them or, on the contrary, to be interested in reducing the traffic and the size of the files by downloading only what's strictly needed.
The structure of the requests is fairly simple, we just have to pass the list of the fields we want, but the TSV format would make harder to keep track of what's inside a file and lead to errors in the ingestion phase.
I propose two changes for which a feedback would be useful:
add an optional parameter with a list of campaign performance
and campaign structure
fields to download, if not specified use the current ones
add a format
parameter which defaults to TSV but can be set to JSON, in which case the files will have a .jsons.gz
extension instead of .csv.gz
and contain a JSON per line with the fields as keys.
Current release of the facebook-python-ads-sdk is 2.11.2.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.