GithubHelp home page GithubHelp logo

project-a / facebook-ads-performance-downloader Goto Github PK

View Code? Open in Web Editor NEW
63.0 63.0 29.0 642 KB

A script for downloading performance and account structure from Facebook Ads API

License: MIT License

Python 100.00%
facebook facebook-ads facebook-ads-sdk python

facebook-ads-performance-downloader's People

Contributors

apisarenco avatar gathineou avatar hendrikmakait avatar jacopofar avatar marcelfriedrichlw avatar martin-loetzsch avatar morganhoward avatar niyooshajafari avatar nklingsporn avatar ralphcw avatar tafkas avatar vaaceph avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

facebook-ads-performance-downloader's Issues

Use logging best practises

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())

Retry when "An unknown error occurred"

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

API deprecated

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?

'charmap' codec can't encode character '\U0001f33f'

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,

The reporting data you are trying to fetch has too many rows

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,

A little simpler data

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 API Issue

Facebook-ads-performance-downloader stopped because Facebook API is using an updated version(5.0)

Make downloader work in parallel for different accounts

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 system cannot find the path specified" (shutil.py)

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'

Use JSON and configurable list of fields

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:

  1. add an optional parameter with a list of campaign performance and campaign structure fields to download, if not specified use the current ones

  2. 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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.