facebookresearch / Ad-Library-API-Script-Repository

GitHub repository of commonly used python scripts that allows everyone to pull data via the Ad Library API
Other
213 stars 84 forks source link

Application does not have permission for this action #3

Closed khaitranvan96kt closed 2 years ago

khaitranvan96kt commented 4 years ago

I get access token from: https://developers.facebook.com/tools/accesstoken

python fb_ads_library_api_cli.py -t <access token> -f 'page_id,ad_snapshot_url,ad_delivery_start_time' -c 'HU' -s '""' --ad-active-status 'ALL' --batch-size '5000' -v save 'output-.json'

And I get the following error, can someone do what I can to run cli?

{
    "error": {
        "message": "Application does not have permission for this action",
        "type": "OAuthException",
        "code": 10,
        "error_subcode": 2332002,
        "is_transient": false,
        "error_user_title": "Authorization and login needed",
        "error_user_msg": "To access the API, you'll need to follow the steps at facebook.com/ads/library/api.",
        "fbtrace_id": "AOxlW9wwYGgl5evOXSPcbiD"
    }
}
skylarcheung commented 4 years ago

Hi khaitranvan96kt and all others who have emailed me asking the same thing. I think by commenting here, I have somehow become the de-facto Facebook Ad Library API troubleshooter. While I still don't really understand how arg parses work, I do hope to offer the little knowledge and wisdom I have in respect to tokens.

Everybody, to begin using the ad library API, you will need to request a token. This is done first through their verification process, which involves some sort of code being mailed to your home address, you will also have to upload a photo of your legal identification (passport). d

For me, the code took about a week to arrive. I was lazy in getting my token/inputting the code, so the code expired and I had to request another one to be mailed to me. This process, I have to say, can be finnicky, as my partner also requested a code but never got one in the mail.

Okay, so now you have entered the verification code, and it appears as though you are an ad-buyer folk for some kind of Facebook page. This is where I got a little lost, but managed to make it out with a token that works. So, first you go to the Graph API Explorer page, where you are presented with a little box on the right hand side with a button that reads generate access token. I think v6.0 is the default version, so I didn't change it to 7.0 on the top bar. Before clicking generate access token, I linked an arbitary facebook app named 'Test 1' and selected 'user token' beneath. For permissions, I just went ahead and selected all the options, just in case. Finally, click generate access token.

Okay, you will probably want to use the access token FOR MORE THAN ONE HOUR (tokens expire, by default, in one hour). So, hover over TOOLS, click ACCESS TOKEN DEBUGGER, then switch the API version from 7.0 to 6.0 on the right, paste your shiny new ABOUT TO EXPIRE token in the box, and click the DEBUG button on the right. Scroll all the way down and click EXTEND ACCESS TOKEN.

Now, there will be a new line reading This new long-lived access token will expire on [DATE ONE MONTH FROM NOW] with a new access token beneath, copy that access token and save it somewhere safe. Do not share your access tokens with others.

POINT TWO: the readme for this is not so great, yes I know, but it is somewhat helpful. If you are using cURL, which very few people use anymore, go and input something like this: curl -G -d "ad_reached_countries=['US']" -d "access_token=ENTERACCESSTOKENINPLACEOFTHESECAPITALS" -d "search_terms='california'" -d "ad_type=POLITICAL_AND_ISSUE_ADS" "https://graph.facebook.com/v6.0/ads_archive" > myresults.json

dfloresgonz commented 3 years ago

So in order to use the AD library API I need to pass the individual verification? too bad it was paused due to covid, so no workaround?

Thanks.

skylarcheung commented 3 years ago

@dfloresgonz I am not sure what the process is now—but from my personal experience trying to bypass the whole identity verification via being snail mailed a code, being snail mailed a code seems to be the only means to pass this necessary verification.

AndrianovVlad commented 3 years ago

Hello!

Thank you that you are sharing your experience.

I have some troubles with some problems in permissions, I have done all as you describe up, but when I run a code with token I have this Error: GraphAPIError: Application does not have permission for this action. I cannot understand, all permissions were given.

Снимок экрана 2021-04-09 в 16 57 49

I am trying to run this code:

def main(): token = "my_token" graph = facebook.GraphAPI(token)

define parameters for request

profile = graph.get_object('ads_archive',fields='page_id,page_name,ad_snapshot_url',search_terms='California',ad_type='POLITICAL_AND_ISSUE_ADS',ad_reached_countries=['US'])
#return desired fields
print(json.dumps(profile, indent=4))
#save results as json file
with open('data.json', 'w', encoding='utf-8') as f:
    json.dump(profile, f, ensure_ascii=False, indent=4)

if name == 'main': main()

I would be thankful for your help.

Best Regards Andrianov Vladislav

skylarcheung commented 3 years ago

@ AndrianovVlad it looks like the token you have is not valid, have you undergone the Identity check necessary to access the Ad Library API? This process entails being snail mailed a code after uploading photo ID documentation.

If you have, also keep in mind that tokens expire within hours if not extended using the debugger.

AndrianovVlad commented 3 years ago

@skylarcheung Thank you! I have sent it yesterday. When I get a code I will try again.

AndrianovVlad commented 3 years ago

@skylarcheung Hello,

I have got token valid key, and I can to research ads, but only in US, Brazil, Great Britain. I would like to find ads in Kazakhstan. Do I understand correctly that through API Library I cannot check such countries as Kazakhstan?

I got this message: "error": { "message": "(#100) Param ad_reached_countries[0] must be one of {BR, GB, US}.", "type": "OAuthException", "code": 100, "fbtrace_id": "AJ-3fbaOaThhgdrhELQ_Cl2" } }

Louislazarus commented 2 years ago

@skylarcheung Hi, thanks for the code! A similar code to this one works great for me. There's just one problem: In the JSON-File there are just 25 ads and a link to a new a page/file where I can find the next 25 and a new link for another 25 ads. So I need to click through all the links to get the ads I need to analyze.

Is there a way to increase the size of the output in c URL code like this one?

curl -G -d "ad_reached_countries=['US']" -d "access_token=ENTERACCESSTOKENINPLACEOFTHESECAPITALS" -d "search_terms='california'" -d "ad_type=POLITICAL_AND_ISSUE_ADS" "https://graph.facebook.com/v6.0/ads_archive" > myresults.json

Thank you.

Louislazarus commented 2 years ago

okay, I just solved it. The parameter: -d "limit=1000" helps out. Thanks anyway.

SusaOP commented 2 years ago

I have been struggling to get this to work for quite awhile now. I verified my developer account already and I have tried to access the Facebook ads_library via this python code and in curl. I get this same error subcode as above. What permissions does it need? I cannot figure out how to ad permissions to curl in CLI or to the python code, even after generating a new token and following the steps linked. I am also using version v14.0 since it was the one there by default.

Any advice? I work in brand protection and my intended use is to help find scam ads. Thanks

jm-yu commented 2 years ago

Hi @SusaOP, did you follow the steps in https://www.facebook.com/ads/library/api. Specifically Step 1 since the user who is querying the API need to be ID confirmed

SusaOP commented 2 years ago

@jm-yu Sorry for slow reply. I originally believed that I had been ID confirmed, as I was able to make some requests from the Graph API Explorer. However, now at Facebook.com/ID I have the error "There's a problem with the info you provided We weren't able to confirm your identity based on the info you provided. As an alternative, you can download a form and take it to a notary to notarize."

I attempted to confirm my identity several times with 2 different forms of ID: US Passport and US Driver's License. They mailed me a confirmation paper a few weeks ago to verify my address, however this address differs from my Passport and License. Would this be the issue? If I go to a notary, what else would I be validating other than confirmed ID and residency in the USA?

Thank you!

vidus commented 2 years ago

You can try getting a better photo. Sometime they reject blurry photos.

From: SusaOP @.> Date: Wednesday, July 20, 2022 at 9:22 PM To: facebookresearch/Ad-Library-API-Script-Repository @.> Cc: Subscribed @.***> Subject: Re: [facebookresearch/Ad-Library-API-Script-Repository] Application does not have permission for this action (#3)

@jm-yuhttps://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fjm-yu&data=05%7C01%7Carpope%40uark.edu%7C0e062fd2299b48978b0408da6abfcb18%7C79c742c4e61c4fa5be89a3cb566a80d1%7C0%7C0%7C637939669237422066%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=eaec08IcyBsFUYwUbUXr2Aq4tEZ1iQ9t3Kl7%2Bi3aVBo%3D&reserved=0 Sorry for slow reply. I originally believed that I had been ID confirmed, as I was able to make some requests from the Graph API Explorer. However, now at Facebook.com/ID I have the error "There's a problem with the info you provided We weren't able to confirm your identity based on the info you provided. As an alternative, you can download a form and take it to a notary to notarize."

I attempted to confirm my identity several times with 2 different forms of ID: US Passport and US Driver's License. They mailed me a confirmation paper a few weeks ago to verify my address, however this address differs from my Passport and License. Would this be the issue? If I go to a notary, what else would I be validating other than confirmed ID and residency in the USA?

Thank you!

— Reply to this email directly, view it on GitHubhttps://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Ffacebookresearch%2FAd-Library-API-Script-Repository%2Fissues%2F3%23issuecomment-1190962833&data=05%7C01%7Carpope%40uark.edu%7C0e062fd2299b48978b0408da6abfcb18%7C79c742c4e61c4fa5be89a3cb566a80d1%7C0%7C0%7C637939669237422066%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=8z9vREGgvVyeIyC0eTsGxLBV65In%2BAcEhb%2ByGH7spvY%3D&reserved=0, or unsubscribehttps://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAAMJEHJ4KZWRRPVCRXQTMZLVVCX4PANCNFSM4NIISXNQ&data=05%7C01%7Carpope%40uark.edu%7C0e062fd2299b48978b0408da6abfcb18%7C79c742c4e61c4fa5be89a3cb566a80d1%7C0%7C0%7C637939669237422066%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=djU94Qr2HZuv5pjjJ68ls0J9uiUVsBv1aXP84or8Z%2BA%3D&reserved=0. You are receiving this because you are subscribed to this thread.Message ID: @.***>

jm-yu commented 2 years ago

@jm-yu Sorry for slow reply. I originally believed that I had been ID confirmed, as I was able to make some requests from the Graph API Explorer. However, now at Facebook.com/ID I have the error "There's a problem with the info you provided We weren't able to confirm your identity based on the info you provided. As an alternative, you can download a form and take it to a notary to notarize."

I attempted to confirm my identity several times with 2 different forms of ID: US Passport and US Driver's License. They mailed me a confirmation paper a few weeks ago to verify my address, however this address differs from my Passport and License. Would this be the issue? If I go to a notary, what else would I be validating other than confirmed ID and residency in the USA?

Thank you!

Based on your comment, I think the issue is that you are not ID confirmed, which do not meet the requirement to access the API. I do not have more context on specifics related to facebook.com/id . If you have questions, you may file a ticket and describe your questions. I will close this issue since it is not related to API or this git repo. Feel free to reopen it or create another one if there are other questions.

poppyseed-bagel commented 1 year ago

Hi,

I'm having the same issue with this API. I can see that my ID has been verified on Facebook. Do I still need to be mailed a code? If so, how do I request to be mailed the code?

Please let me know.

Thanks!

HippocSoilih commented 1 year ago

Hi,

I'm having the same issue with this API. I can see that my ID has been verified on Facebook. Do I still need to be mailed a code? If so, how do I request to be mailed the code?

Please let me know.

Thanks!

Hello, Did you archive to solve the issue? I'm experiencing the same thing.

Thank you !

poppyseed-bagel commented 1 year ago

Hi, i did need to get mailed the code in the end. however they didn't accpet my id and are making me get a paper notarized and they won't accept the upload of that PDF now so I'm still stuck

mosha101 commented 1 year ago

i have a similar issue. im my case, I get a message "There's a problem with the info you provided We weren't able to confirm your identity based on the info you provided. As an alternative, you can download a form and take it to a notary to notarize."

However, I don't know where this form is or where to download it from. There is no link or indication of where to find this form.

iamsashwin commented 7 months ago

I get access token from: https://developers.facebook.com/tools/accesstoken

python fb_ads_library_api_cli.py -t <access token> -f 'page_id,ad_snapshot_url,ad_delivery_start_time' -c 'HU' -s '""' --ad-active-status 'ALL' --batch-size '5000' -v save 'output-.json'

And I get the following error, can someone do what I can to run cli?

{
    "error": {
        "message": "Application does not have permission for this action",
        "type": "OAuthException",
        "code": 10,
        "error_subcode": 2332002,
        "is_transient": false,
        "error_user_title": "Authorization and login needed",
        "error_user_msg": "To access the API, you'll need to follow the steps at facebook.com/ads/library/api.",
        "fbtrace_id": "AOxlW9wwYGgl5evOXSPcbiD"
    }
}

Can you share me the python code..?

mhwahla commented 3 months ago

I WAS FACING THIS ISSUE AND WHAT I DID TOOK 5 MINTS TO SOLVE I WAS FACING THIS ISSUE AND WHAT I DID TOOK 5 MINTS TO SOLVE I WAS FACING THIS ISSUE AND WHAT I DID TOOK 5 MINTS TO SOLVE I WAS FACING THIS ISSUE AND WHAT I DID TOOK 5 MINTS TO SOLVE

screencapture-localhost-8888-notebooks-fb-ads-library-tool-ipynb-2024-06-06-11_55_30