i'm currently serching for a solution to get all ad links pointing to my Website via the Facebook Marketing API. My current approch is collecting all ads in the Account:
curl -G \
-d "level=ad" \
-d "fields=spend,impressions,ad_id" \
-d "date_preset=yesterday" \
-d "access_token=<token>" \
"https://graph.facebook.com/v2.9/act_<id>/insights"
and than loop over all Ids
curl -G \
-d "fields=id,name,body" \
-d "level=ad" \
-d "access_token=<token>" \
"https://graph.facebook.com/v2.9/<ad-id>"
Sadly if I use the ad-id from the insights I get the Error : "message":"(#100) Tried accessing nonexisting field (link) on node type (Adgroup)". Wy does the Insights return a Adgroup for a ad? Does anybody know a workaround?
All the best
Daniel
There is no field called body
in Ads. Your call is failing because FB is telling you that you cannot retrieve a non-existing field. You can look up the available fields for "Ad" object at https://developers.facebook.com/docs/marketing-api/reference/adgroup
Also, I would try using graph.facebook.com/v2.9/act_<id>/ads
to get the ad ids instead of insights
call. You will get a cleaner JSON response like this:
`
{
"data": [
{
"id": "<ad_id_1>"
},
{
"id": "<ad_id_2>"
},
....
`