3

I'm trying to sync a custom audience with the php fb sdk. My script looks like this:

foreach ($users->pluck('email') as $email) {
    $hashed[] = [hash('sha256', $email)];
}
    
try {
    (new CustomAudience('custom-audience-id'))
      ->createUsersReplace([], [
          'payload' => [
              'schema' => [
                  'EMAIL',
              ],
              'data' => $hashed,
          ],
          'session' => [
              'session_id' => rand(1, 10000000),
              'batch_seq' => 1,
              'last_batch_flag' => true,
              'estimated_num_total' => count($hashed),
          ],
      ]);
} catch (Exception $ex) {
    $this->info($ex->getMessage());
}

The script runs successfully, when I look into the history tab FB is telling me the x records have been replaced successfully:

enter image description here

However, the size is not updated (after processing for a couple of hours):

enter image description here

When I upload the records manually through an excel sheet the size is updated correctly. Obviously, something is wrong with my PHP script but can't figure out what's wrong.

Hedayatullah Sarwary
  • 2,664
  • 3
  • 24
  • 38
Jamie
  • 10,302
  • 32
  • 103
  • 186
  • if you only update email try pass `schema` as string and hash data as one-dimensional array: `'schema' => "EMAIL"` and `$hashed[] = hash('sha256', $email);` – Chinh Nguyen Jun 10 '21 at 08:28
  • Thanks but that's not working. `(#2650) Failed to update the custom audience: This audience was created from data source FILE_IMPORTED.MULTI_HASHES, which does not support data source FILE_IMPORTED.HASHES_OR_USER_IDS.` @ChinhNguyen – Jamie Jun 10 '21 at 09:01
  • What is Type of Custom Audience? Is it CUSTOM? – MHIdea Jun 10 '21 at 11:21
  • Yes it's custom @MHIdea – Jamie Jun 10 '21 at 12:19
  • @Jamie change $hashed data to 1-D array as Chinh Nguyen mentioned and with that also change `'data' => [$hashed]` to make it 2-D array and check working or not – Haridarshan Jun 10 '21 at 12:39
  • When I do that I keep getting `(#2650) Failed to update the custom audience: This audience was created from data source FILE_IMPORTED.MULTI_HASHES, which does not support data source FILE_IMPORTED.HASHES_OR_USER_IDS.` @Haridarshan – Jamie Jun 10 '21 at 14:26
  • What is the output of this `curl -G \ -d 'access_token=' \ https://graph.facebook.com/v11.0/\?fields\=data_source | jq` – Haridarshan Jun 10 '21 at 15:22
  • Also, what is the response of `createUsersReplace`? – Haridarshan Jun 10 '21 at 15:25
  • @Haridarshan when I change everything back too what I had the response is a `FacebookAds\Object\CustomAudience` object so that's good. But the message smaller then 1000 keeps showing up in my fb business manager. So basically the audience is useless. When I execute the command you've given I get `Could not resolve host`. Seriously FB api is terrible :) – Jamie Jun 11 '21 at 08:45
  • count of `$hashed` records and excel sheet rows are same or different? – Haridarshan Jun 11 '21 at 11:11

1 Answers1

0

I think you are trying to add custom audience to your audience set for digital marketing. The thing is Facebook ads take 24 hours before reflecting the scripting results. As your initial audience set was less then 1000 it will take 24 hours to update the target audience. So wait for that time duration and then check for other options. Also cross check with pixel official code if they have updated anything.