Hello,

I'm trying set up a call to the API that automatically add's phone numbers 
or User ids to the designated list's. 

I have already accomplished this with Emails.

What I have done is basically copied the script for emails and changed it 
to be for hashedPhonenumber or userId.  The api is accepting the numbers no 
errors fired but the lists aren't populating. It says underneath in AdWords 
that they are populating and AdWords is displaying the right last upload 
times. But the lists remain at 0.

I wanted to make sure this wasn't down to the code at my side.
Below is the code for user id & telephones.

For user id:

<?php
if (!defined('sfpaa_dir'))
    define('sfpaa_dir', plugin_dir_path( __FILE__ ));

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->setUserId (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 User Id'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);
  }
}



for telephone:
<?php
if (!defined('sfpaa_dir'))
    define('sfpaa_dir', plugin_dir_path( __FILE__ ));

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);
  }
}



-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads API Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"AdWords API and Google Ads API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/92e39871-f0aa-42b9-9ea9-51d69c2d28f0%40googlegroups.com.

Reply via email to