如何通过 Facebook API 列出自定义受众?

How to list custom audiences via Facebook API?

我可以使用 Facebook 图 API 创建受众,但是有没有办法在不知道他们 ID 的情况下列出 audiences

import json, requests
response = requests.get(
    f"https://graph.facebook.com/v9.0/search?access_token={FB_TOKEN}",  #&fields={fields}",
    params=f"ad_account_id={AD_ACCOUNT_ID}",
    timeout=30
)
print(response.text)
print(json.dumps(response.json(), indent=4, sort_keys=False))

只给我这个:

<Response [400]>
{
    "error": {
        "message": "(#27) This method is only available to Workplace apps.",
        "type": "OAuthException",
        "code": 27,
        "fbtrace_id": "xxx"
    }
}

感谢,这是答案:

import json, requests


fields = "id,name,description"

response = requests.get(
    f"https://graph.facebook.com/v9.0/{AD_ACCOUNT_ID}/customaudiences?access_token={FB_TOKEN}&fields={fields}",
    timeout=30
)

print(json.dumps(response.json(), indent=4, sort_keys=False))

我还必须使用 f"https://graph.facebook.com/v9.0/me/adaccounts?access_token={FB_TOKEN}&fields={fields}", 从令牌中获取 AD_ACCOUNT_ID 以查看它应以“act_”开头以避免此错误消息:

<Response [400]>
{
    "error": {
        "message": "Unsupported get request. Object with ID 'xxx' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api",
        "type": "GraphMethodException",
        "code": 100,
        "error_subcode": 33,
        "fbtrace_id": "xxx"
    }
}