0

Can any one tell me the correct way of getting the ids of account which are sharing one Custom Audience i.e. adaccounts
Query in PHP using API v2.4

$account = new AdAccount($accountId);
    $fields = array(
        CustomAudienceFields::ID,
        CustomAudienceFields::NAME, 
        CustomAudienceFields::SUBTYPE,
        CustomAudienceFields::ACCOUNT_ID,
        CustomAudienceFields::ADACCOUNTS,
    );
    $params = array('filters'=>array(
                    array(
                        'field'=>'subtype',
                        'type'=>'in',
                        'value'=>['WEBSITE','CUSTOM'],
                    ),
                ),);    

    $CustomAudience = $account->getCustomAudiences($fields,$params);

Results

[adaccounts] => Array ( [data] => Array ( [0] => 9.1432423423488E+14 [1] => 8.9623423402405E+14 [2] => 8.71252342345443E+14 [3] => 8.832242342342387E+14 [4] => 8.92234234079338E+14 ) )

Note: I added this property myself in CustomAudienceFileds.php:
"CustomAudienceFields::ADACCOUNTS"

PROBLEM
All values are in float or I don't know what these values are actually. I converted these values to int but they appeared to be in negative and wrong account ids.
Please let me know what what and where I am wrong.

Its working absolutely fine in Graph Api Explorer tool when I Query this:
Query in Graph Api Explorer v2.4:
act_34234234234344/customaudiences?fields=adaccounts
Results:
"adaccounts": { "data": [ 534534534534555, 564563453454534, 345345345345345, 234234234234234 ] }

Tami
  • 576
  • 7
  • 18
  • It looks like your PHP isn't able to handle the 64 bit ints in the response - does it work with other responses from the API? Also, does it work with Facebook's main SDK or are you only trying with the 'ads' specific version? – Igy Aug 05 '15 at 18:39
  • I am using Facebook ads sdk. On other places I am fetching accounts ids (64 bit int) and they are displayed properly!!! – Tami Aug 06 '15 at 08:49
  • On what platform/OS? Does your install of PHP support 64 bit ints? – Igy Aug 06 '15 at 15:14
  • OS: Windows 7 64 bit and PHP 5.5.2. Thanks for your moral support lgy :) i found a workaround for this problem which i will write as answer. – Tami Aug 06 '15 at 15:27

1 Answers1

0

Actually the values returned in response were in scientific notation, so simply iterated through each value(adaccountid) and convert it into integer using spinrtf, like this:

$i =0;
foreach ($CustomAudience as $audience) {
  foreach($audience->adaccounts['data'] as $accountid)
  {
    if($i ==0)
        $info["adaccountsIds"] =  sprintf('%.0F',$accountid);
    else
        $info["adaccountsIds"] .= ','.sprintf('%.0F',$accountid);

   $i++;
  }
}  

I will not say it answer, its a work around. Still more answers are welcome

Tami
  • 576
  • 7
  • 18