简体   繁体   中英

I'm trying to use the Facebook API to get lead information on an ad, but I keep getting an error message

So, I'm trying to use Python and the Facebook API to get the lead info for an ad. I'm following the instructions under Bulk Read on this page: https://developers.facebook.com/docs/marketing-api/guides/lead-ads/retrieving . And my code looks like this:

from facebook_business.adobjects.ad import Ad
from facebook_business.adobjects.lead import Lead
from facebook_business.api import FacebookAdsApi
import os

access_token = os.getenv('FB_ACCESS_TOKEN')
app_secret = os.getenv('FB_APP_SECRET')
app_id = os.getenv('FB_APP_ID')
id = '23850504679460681'
FacebookAdsApi.init(access_token=access_token)

fields = [
]
params = {
}
print(Ad(id).get_leads(
  fields=fields,
  params=params,
  ))

When I run this, I get this error message:

C:\Users\Joseph\Desktop\python_code\Facebook API>python leadget.py
Traceback (most recent call last):
  File "C:\Users\Joseph\Desktop\python_code\Facebook API\leadget.py", line 16, in <module>
    print(Ad(id).get_leads(
  File "C:\Users\Joseph\AppData\Local\Programs\Python\Python310\lib\site-packages\facebook_business\adobjects\ad.py", line 622, in get_leads
    return request.execute()
  File "C:\Users\Joseph\AppData\Local\Programs\Python\Python310\lib\site-packages\facebook_business\api.py", line 677, in execute
    cursor.load_next_page()
  File "C:\Users\Joseph\AppData\Local\Programs\Python\Python310\lib\site-packages\facebook_business\api.py", line 841, in load_next_page
    response_obj = self._api.call(
  File "C:\Users\Joseph\AppData\Local\Programs\Python\Python310\lib\site-packages\facebook_business\api.py", line 350, in call
    raise fb_response.error()
facebook_business.exceptions.FacebookRequestError:

  Message: Call was not successful
  Method:  GET
  Path:    https://graph.facebook.com/v13.0/23850504679460681/leads
  Params:  {'summary': 'true'}

  Status:  400
  Response:
    {
      "error": {
        "message": "(#100) Requires pages_manage_ads or leads_retrieval permission to manage the object",
        "type": "OAuthException",
        "code": 100,
        "fbtrace_id": "ALhUN1djYRl_0HTb4RHZuHF"
      }
    }

I've checked, and both I and the app have those permissions. What am I doing wrong?

Hope it's not too late for you but it seems to need more permissions to get leads information.
you can do this in your facebook developer application

像这样

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM