Query issue
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
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
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 @noradioactive ,
Looks like you need to install the module requests. You can find instructions in the README's Requirements section to install requests
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
- https://stackoverflow.com/questions/74256342/python-module-not-found-even-though-its-installed
- https://stackoverflow.com/questions/45693420/python-modulenotfounderror-but-module-is-installed
- https://stackoverflow.com/questions/66728011/module-not-found-even-after-pip-install
From what i understand:
- If you run
pip -Vin the cli it will display where pip will install your module. - If you run
import sysconfig; print(sysconfig.get_paths()["purelib"])in python, it will show where python looks for packages. - You should be able to install the module in the right place by running
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