Telephone list not populating

45 views
Skip to first unread message

Darren Clyde

unread,
Nov 8, 2019, 7:31:05 PM11/8/19
to AdWords API and Google Ads API Forum
I've been uploading telephone numbers to a remarketing list using the api. But for some reason, the list says populating and the correct last update shows but it is not increasing in number. I already have an email list that works just fine. Is there something wrong with the code below? why would it work for emails and not phones?

Here is the code I use:
require 'AddPhone.php';

            // Set parameters
            $EMAILS = $phoneNumbers;
            $LIST_ID = $listID;
            $CLIENT_CUSTOMER_ID = $clientID;

            // Add e-mail addresses to the list
            AddCrmBasedUserList::authenticateAndRun( $EMAILS, $LIST_ID, $CLIENT_CUSTOMER_ID );




Here is the addPhone.php


require __DIR__ . '/vendor/autoload.php';

use Google\AdsApi\AdWords\AdWordsServices;
use Google\AdsApi\AdWords\AdWordsSession;
use Google\AdsApi\AdWords\AdWordsSessionBuilder;
use Google\AdsApi\AdWords\v201809\cm\Operator;
use Google\AdsApi\AdWords\v201809\rm\AddressInfo;
use Google\AdsApi\AdWords\v201809\rm\AdwordsUserListService;
use Google\AdsApi\AdWords\v201809\rm\CrmBasedUserList;
use Google\AdsApi\AdWords\v201809\rm\Member;
use Google\AdsApi\AdWords\v201809\rm\MutateMembersOperand;
use Google\AdsApi\AdWords\v201809\rm\MutateMembersOperandDataType;
use Google\AdsApi\AdWords\v201809\rm\MutateMembersOperation;
use Google\AdsApi\AdWords\v201809\rm\UserListOperation;
use Google\AdsApi\Common\OAuth2TokenBuilder;

class AddCrmBasedUserList {
  public static function run(AdWordsServices $adWordsServices,
      AdWordsSession $session, array $emails, int $listId, bool $quiet = True) {
    $userListService =
        $adWordsServices->get($session, AdwordsUserListService::class);

    // Create operation to add members to the user list based on email
    // addresses.
    $mutateMembersOperations = [];
    $mutateMembersOperation = new MutateMembersOperation();
    $operand = new MutateMembersOperand();
    $operand->setUserListId($listId);

    $members = [];
    // Hash normalized email addresses based on SHA-256 hashing algorithm.
    foreach ($emails as $email) {
      $memberByEmail = new Member();
      $memberByEmail->setHashedPhoneNumber (self::normalizeAndHash($email));
      $members[] = $memberByEmail;
    }

    // Add members to the operand and add the operation to the list.
    $operand->setMembersList($members);
    $mutateMembersOperation->setOperand($operand);
    $mutateMembersOperation->setOperator(Operator::ADD);
    $mutateMembersOperations[] = $mutateMembersOperation;

    // Add members to the user list based on email addresses.
    $result = $userListService->mutateMembers($mutateMembersOperations);

    // Print out some information about the added user list.
    // Reminder: it may take several hours for the list to be populated with
    // members.
    foreach ($result->getUserLists() as $userList) {
      $session->getSoapLogger()->info(sprintf(
          "%d Phone Numbers's were uploaded to user list with name '%s' and ID"
              . " %d and are scheduled for review.\n",
          count($emails),
          $userList->getName(),
          $userList->getId()
      ));
    }
  }

  private static function normalizeAndHash($value) {
    return hash('sha256', strtolower(trim($value)));
  }

  public static function authenticateAndRun(array $emails, int $listId, string $clientCustomerId) {
    // Generate a refreshable OAuth2 credential for authentication.
    $oAuth2Credential = (new OAuth2TokenBuilder())
        ->fromFile()
        ->build();

    // Construct an API session configured from a properties file and the OAuth2
    // credentials above.
    $session = (new AdWordsSessionBuilder())
        ->fromFile()
        ->withOAuth2Credential($oAuth2Credential)
        ->withClientCustomerId($clientCustomerId)
        ->build();
    self::run(new AdWordsServices(), $session, $emails, $listId);
  }
}




Google Ads API Forum Advisor Prod

unread,
Nov 11, 2019, 10:19:33 AM11/11/19
to dar...@leonardholdings.co.uk, adwor...@googlegroups.com
Hello Darren,

Your code looks good. Could you please confirm, if you are uploading those phone numbers to the user list that already had email? If yes, then please note that one user list can target audiences based on one kind of id only. In such case you can create a new user list with those normalized phone-numbers. If the issue persists, please share the request and response log of the user list update operation without redacting any information using reply privately to the author option.

Regards,
Sai Teja, Google Ads API Team

ref:_00D1U1174p._5001UMWlCu:ref
Reply all
Reply to author
Forward
0 new messages