Get reach estimate with PHP API

233 views Asked by At

I spent hours trying to get reach estimate using PHP SDK. The problem I am having is simply not knowing how to use function "getReachEstimate(.., ..)" It is not explained anywhere in a way that I would be able to understand.

If someone could give me a code example of using this function would be great, or any other way of geting reach estimate using PHP.

2

There are 2 answers

0
Serg.ID On

The same GET request through the SDK

$response = $api->call(
        "/".$ad_account_id."/reachestimate",
        RequestInterface::METHOD_GET,
        array(
            'targeting_spec' => json_encode($targeting),
            'currency'       => 'USD'
        )
    );
return $response->getContent();

Where $ad_account_id looks like act_XXXXXXX

0
RisingSun On

I have searched for documentation on the exact function and there is no documentation on that function anywhere although I was able to find the actual function in the SDK. I ended up writing a curl call. I am using the targeting specs for a campaign to query it. Here is the call.

        $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://graph.facebook.com/v2.4/$ad_account_id/reachestimate" .
      '?access_token=' . $accessToken . '&' .
      'targeting_spec=' . urlencode(json_encode($targeting)) . '&' .
      'currency=' . 'USD'
    );
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    $result = curl_exec($ch);
    curl_close($ch);