Ad-Library-API-Script-Repository icon indicating copy to clipboard operation
Ad-Library-API-Script-Repository copied to clipboard

PermissionError: [Errno 13] Permission denied:

Open noralegrand opened this issue 1 year ago • 6 comments

Hello,

I am running this command on my terminal :

C:\Ad-Library-API-Script-Repository-main\python> py fb_ads_library_api_cli.py -t (token) -f "id,page_id,page_name,ad_creative_bodies,spend,demographic_distribution,bylines,ad_delivery_start_time" -c "CA" -s "climate" --after-date "2024-05-01" save_to_csv file.csv

And I get the following error :

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 96, in save_to_csv with open(output_file, "w") as csvfile: ^^^^^^^^^^^^^^^^^^^^^^ PermissionError: [Errno 13] Permission denied.

I have tried adding "encoding="utf-8" in the fb_ads_library_api_operators file, but it didn't work (i am able to get one dataset then i get the same error all over again)

Does anyone have a solution ? i'm not sure I understand how the Permission system works in the Graph Api.

noralegrand avatar May 30 '24 09:05 noralegrand

Could it be an issue with your token? I just used your exact command (with my own token) without adding anything to any code and was able to get this output file. file.csv

kimberlyzhu avatar May 31 '24 00:05 kimberlyzhu

Have you tried twice ? after trying a second time i get the "permission denied" error, then nothing works anymore. What permissions should i have to have access to the data ?

noralegrand avatar Jun 03 '24 08:06 noralegrand

Yes i tried twice:

kimberlyzhu@kimberlyzhu-mbp python % python3 fb_ads_library_api_cli.py -t <token> -f "id,page_id,page_name,ad_creative_bodies,spend,demographic_distribution,bylines,ad_delivery_start_time" -c "CA" -s "climate" --after-date "2024-05-01" save_to_csv file.csv
Successfully wrote data to file: file.csv
kimberlyzhu@kimberlyzhu-mbp python % python3 fb_ads_library_api_cli.py -t <token> -f "id,page_id,page_name,ad_creative_bodies,spend,demographic_distribution,bylines,ad_delivery_start_time" -c "CA" -s "climate" --after-date "2024-05-01" save_to_csv file.csv
Successfully wrote data to file: file.csv

Following the steps on the Ad Library API should give you the permissions you need.

kimberlyzhu avatar Jun 03 '24 17:06 kimberlyzhu

Also, looking at your error message, could it possibly be an issue with your system in overwriting the file.csv that already exists? Especially given the command doesn't work on the second try.

kimberlyzhu avatar Jun 03 '24 18:06 kimberlyzhu

I usually overwrite on the same file because i update it with recent data, but that might be the problem. On the Graph Api, there is a bunch of permissions to choose in "permissions". I randomly selected "public-profile", but i don"t know which one i should have.

noralegrand avatar Jun 04 '24 08:06 noralegrand

how do I get only political and issue ads ? The datasets that i get are always dirty with "all_data".

noralegrand avatar Jun 06 '24 09:06 noralegrand