Vagish Dilawari
Vagish Dilawari

Reputation: 31

What's the API method to retrieve the destination website URL of a Facebook ad?

(1) I need to extract the link inside a facebook ad. When creating a facebook ad , we need to fill in destination, where we need to fill website url, how can I get this value from some facebook api. Basically the link where the ad redirects to. (2) Also, is there a way where I can get all attributes/properties of an ad, which were filled in while creating the ad, through some api, such as name, body, website_url.

The input that I can give is the ad_id

I have tried https://graph.facebook.com/v17.0/23855312168950236?fields=name api, wherein I have passed name as a param, and the response is { "name": "Testing fbp cookies", "id": "23855312168950236" } . This response is fine.

As per the documentation, I used object_url, link_url and a few other params as , https://graph.facebook.com/v17.0/23855312168950236?fields=object_url, but then the response changes to , { "error": { "message": "(#100) Tried accessing nonexisting field (object_url) on node type (Ad)", "type": "OAuthException", "code": 100, "fbtrace_id": "AiMmHEZkpParXv9soPnBPCg" } }

api cURL referred from - https://developers.facebook.com/docs/marketing-api/creative query params list referred from - https://developers.facebook.com/docs/marketing-api/reference/ad-creative

also tried - Facebook Ads Insights API - Requesting Website URL Parameter but same error

** NOTE - I AM USING CREATIVE_ID AS THE AD_ID ITSELF**

Upvotes: 3

Views: 1224

Answers (1)

Brad Smith
Brad Smith

Reputation: 1

This approach worked for me:

params = {
    "fields": "asset_feed_spec", 
    "access_token": my_access_token,  # Replace with your actual access token
    "app_id": my_app_id  # Replace with your actual access token
}

url = "https://graph.facebook.com/v18.0/{0}".format(your_creative_id)
response = requests.get(url, params=params)
print(response.text)

The website_url is buried in the resulting asset_feed_spec JSON. The FB docs are near impossible to follow and split across V2 and V3 of python and various SDK tooling. Here's what got me to what I needed:

https://developers.facebook.com/docs/marketing-api/ad-creative/asset-feed-spec/

Good luck!

Upvotes: 0

Related Questions