Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query issue #28

Open
noralegrand opened this issue Jul 31, 2023 · 10 comments
Open

Query issue #28

noralegrand opened this issue Jul 31, 2023 · 10 comments

Comments

@noralegrand
Copy link

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

@kimberlyzhu
Copy link

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

@noralegrand
Copy link
Author

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
from fb_ads_library_api import FbAdsLibraryTraversal
File "C:\Ad-Library-API-Script-Repository-main\python\fb_ads_library_api.py", line 13, in
import requests
ModuleNotFoundError: No module named 'requests'

@kimberlyzhu
Copy link

Hi @noradioactive ,

Looks like you need to install the module requests. You can find instructions in the README's Requirements section to install requests

@noralegrand
Copy link
Author

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
from fb_ads_library_api_utils import get_country_code, is_valid_fields
File "C:\Ad-Library-API-Script-Repository-main\python\fb_ads_library_api_utils.py", line 9, in
from iso3166 import countries
ModuleNotFoundError: No module named 'iso3166'

PS C:\Ad-Library-API-Script-Repository-main\python> pip install iso3166
Requirement already satisfied

@kimberlyzhu
Copy link

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:

  • If you run pip -V in 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 .

@noralegrand
Copy link
Author

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
main()
File "C:\Ad-Library-API-Script-Repository-main\python\fb_ads_library_api_cli.py", line 134, in main
save_to_csv(
File "C:\Ad-Library-API-Script-Repository-main\python\fb_ads_library_api_operators.py", line 97, in save_to_csv
csvfile.write(output)
File "C:\Users\norad\AppData\Local\Programs\Python\Python311\Lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeEncodeError: 'charmap' codec can't encode characters in position 23868-23874: character maps to

@kimberlyzhu
Copy link

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

@noralegrand
Copy link
Author

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

@kimberlyzhu
Copy link

@noradioactive if your access token doesn't last long enough, you may need to modify your query to search for a more specific search.

@noralegrand
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants