Open noralegrand opened 1 year ago
Hi @noradioactive,
For your specific error OSError: [Errno 22] Invalid argument
, this stack overflow post should provide some context. This seems to be an issue for specific Python versions as well as Windows where our default start date of 1970-01-01
is too early. You should keep the --after-date
argument to prevent this issue.
If the result you get back when including the --after-date
argument is an empty CSV, then it's because you need to include ad_delivery_start_time
as a request column in the input.
The following query works:
python3 fb_ads_library_api_cli.py -t <access-token> -f "id,page_id,page_name,spend,demographic_distribution,bylines,ad_delivery_start_time" -c "CA" -s "." --after-date "2023-07-01" save_to_csv data.csv
Hi Kimberly,
Thanks for the tip. However, i'm facing a new error with the query you suggested :
Traceback (most recent call last):
File "C:\Ad-Library-API-Script-Repository-main\python\fb_ads_library_api_cli.py", line 11, in
Hi Kimberly,
here's new error after installing requests :
Traceback (most recent call last):
File "C:\Ad-Library-API-Script-Repository-main\python\fb_ads_library_api_cli.py", line 13, in
PS C:\Ad-Library-API-Script-Repository-main\python> pip install iso3166 Requirement already satisfied
Hi @noradioactive,
Can you try pip3 install iso3166
. Otherwise, this seems to be a setup issue for your python modules.
These posts might help you debug your setup
From what i understand:
pip -V
in the cli it will display where pip will install your module.import sysconfig; print(sysconfig.get_paths()["purelib"])
in python, it will show where python looks for packages.python3 -m pip install iso3166
.Hi Kimberly,
It worked, however it raised another error. I couldn't find a solution on stack overflow that is accurate with my case :
Traceback (most recent call last):
File "C:\Ad-Library-API-Script-Repository-main\python\fb_ads_library_api_cli.py", line 147, in
Hi @noradioactive ,
You might need to modify the code to write with utf-8
encoding: https://stackoverflow.com/questions/27092833/unicodeencodeerror-charmap-codec-cant-encode-characters
Hi Kimberly, I was able to modify the code with the utf-8 encoding and run a query. But it keeps loading until my token expires and I get an error. Here's the query :
py fb_ads_library_api_cli.py -t (token) -f "id,page_id,page_name,spend,demographic_distribution,bylines,ad_delivery_start_time" -c "CA" -s "." --after-date "2023-08-15" save_to_csv data.csv
@noradioactive if your access token doesn't last long enough, you may need to modify your query to search for a more specific search.
Hi Kimberly, This has been working so far, thanks a lot. Is it possible to change the default "ALL" ad_type value to "POLITICAL_AND_ISSUE_ADS" in my query ? or any other default values ? Thanks
Hi, Has anyone else run into this issue before ? Traceback (most recent call last): File "C:\Ad-Library-API-Script-Repository-main\python\fb_ads_library_api_cli.py", line 147, in
main()
File "C:\Ad-Library-API-Script-Repository-main\python\fb_ads_library_api_cli.py", line 138, in main
get_operators()[opts.action](
File "C:\Ad-Library-API-Script-Repository-main\python\fb_ads_library_api_operators.py", line 35, in count_ads
for ad_archives in generator_ad_archives:
File "C:\Ad-Library-API-Script-Repository-main\python\fb_ads_library_api.py", line 80, in _get_ad_archives_from_url
start_time_cutoff_after = datetime.strptime(after_date, "%Y-%m-%d").timestamp()
OSError: [Errno 22] Invalid argument
Here is the query that i ran : py fb_ads_library_api_cli.py -t (access-token) -f "id,page_id,page_name,spend,demographic_distribution,bylines" -c "CA" -s "." --after-date "2023-07-01" save_to_csv data.csv