Chris
Chris

Reputation: 301

Facebook Graph API php cURL request returns partial data for AdCreative, despite sufficent permission (no error given)

I am working on a PHP-based web app that's to be used internally by my agency's 3 team members, to read campaign and ads data. Ideally, for the sake of security, the tool would never have the ability to edit ads. It's a comparatively simple tool, I think. So I opted for cURL requests rather than using the PHP Business SDK.

The App is in 'In Development' mode, and it's being access by a System User in Business Manager whose token permissions are:

The System User has been given access to the following Assets:

The Ad Account. Permissions granted: View Performance
The Page. Permissions granted: View Page Performance

With those settings in place, the application is able to pull almost everything needed to view the info we require for our campaigns/ad sets/ads. I'm quite proud of it. But there's only one problem. I can't seem to get the destination URL for any ads through any API requests.

From what I understand, I need to query an ad's AdCreative.

With php cURL requests like this:

$access_token = "REDACTED";
$app_secret = "REDACTED";
$appsecret_proof = hash_hmac('sha256', $access_token, $app_secret);
$handle = curl_init();

$url = "https://graph.facebook.com/v7.0/23845023771530707?fields=object_story_spec,thumbnail_url,link_url,call_to_action_type&access_token=$access_token&appsecret_proof=$appsecret_proof";


curl_setopt($handle, CURLOPT_URL, $url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($handle);
curl_close($handle);

$result = json_decode($output,true);
echo "<pre>";print_r($result);echo "</pre>";

I get the following return:

Array
(
    [object_story_spec] => Array
        (
            [page_id] => 104422504276761
        )

    [thumbnail_url] => https://external.xx.fbcdn.net/safe_image.php?d=AQCP_C2YI....Shortened here for clarity of this post
    [id] => 23845023771530707
)

In short, only about half of the fields seem to populate. I really need to get the final destination URL of an ad. I do not get the link_url or call_to_action_type fields that I requested. :(

So, I'm wondering things like...

  1. Am I going about this wrong? Is AdCreative the wrong way to query this info?
  2. Am I somehow still lacking permissions?
  3. Am I unable to get these fields because the App in still 'In Development'? Do I need to submit the App for Review?

Sorry there are several questions here rolled into one post.

Upvotes: 0

Views: 839

Answers (1)

David Tedman-Jones
David Tedman-Jones

Reputation: 513

The field object_story_spec in the creative object is only present if the ad created a new page-post on publish. It won't be present if the ad was created referencing an existing page-post.

Fortunately, the reference to the created/referenced page-post effective_object_story_id should exist on every ad-creative.

You can query the page-post via /{effective_object_story_id}?fields=... to find the data that would have otherwise existed in object_story_spec.

ad-creative: https://developers.facebook.com/docs/marketing-api/reference/ad-creative

page-post: https://developers.facebook.com/docs/graph-api/reference/page-post

Upvotes: 1

Related Questions