0

How can we get the list all the "active" and "live" Facebook ads for any given ad account and get the ID of unpublished posts attached to them?

I am trying to retrieve all the comments on unpublished posts but using the graph API only gives you the ability to query the "X" latest unpublished posts, whether or not these are still being currently used on a "live" ad. Unpublished posts that are not attached to a "live" ad will not get comments anymore. I'd like to narrow down my results to unpublished post that are still being promoted right now (and avoid querying the others).

Looks like we have a combine queries on the ads API + the graph API, but not sure how to proceed. Has anyone already had that need?

1 Answers1

2

You'll need several queries (or possibly one batch query) so you'll want to write a script for this. You can use curl or one of the official FB Marketing API SDKs. The examples I'll give are all in curl for simplicity.

You'll need to query for active adgroups and then for each adgroup retrieve its adcreative ID in order to get the creative's object_story_id. The object_story_id corresponds to the unpublished page post from which you can retrieve comments.

Live ads are ads in a active state, so you'll want to query for adgroups with adgroup_status field value of "ACTIVE".

To get active ads (adgroups) for your account and API version v2.4:

curl -G \
-d "access_token=<ACCESS_TOKEN>" \
"https://graph.facebook.com/v2.4/<AD_ACCOUNT_ID>/adgroups?adgroup_status=["ACTIVE"]"

for each adgroup ID query for the object_story_id within the ad's creative

curl -G \
-d "access_token=<ACCESS_TOKEN>" \
"https://graph.facebook.com/v2.4/<ADGROUP_ID>?fields=creative{object_story_id}"

(by the way, that query uses FB field expansion https://developers.facebook.com/docs/graph-api/using-graph-api/v2.3#fieldexpansion)

using the object_story_id you can retrieve the post comments

curl -G \
-d "access_token=<ACCESS_TOKEN>" \
"https://graph.facebook.com/v2.4/<OBJECT_STORY_ID>/comments"

Adgroup API docs are at https://developers.facebook.com/docs/marketing-api/adgroup/v2.4#read-adaccount and adcreative at https://developers.facebook.com/docs/marketing-api/adcreative/v2.4. See also https://developers.facebook.com/docs/marketing-api/getting-started#structure for details on FB ad object structure.

Or instead you can try using the FB Batch system to make one request https://developers.facebook.com/docs/graph-api/making-multiple-requests though I'm not certain if this particular goal is achievable.

bjeavons
  • 1,123
  • 6
  • 16