Migration from AdWords API to Google Ads API for upload to Audience help

221 views
Skip to first unread message

derek

unread,
Nov 20, 2022, 10:26:00 PM11/20/22
to Google Ads API and AdWords API Forum
Hi
I recently took over this process to upload user lists to Google audience.
I need to migrate it from AdWords API (Java client library) to the Google Ads API (Java client library).
I am not able to find the equivalent Ads API of the AdWords API used.

Still trying to understand the process and about Google Ads Audience but I think these methods are the main part of the process.

    private void getUserList(){
        log.info("get user list [{}]", audienceId);
        int offset = 0;
        //MR54558 reset userList for each List ID
        userList = null;
        SelectorBuilder builder = new SelectorBuilder();
        Selector selector = builder
                    .fields(AdwordsUserListField.Id, AdwordsUserListField.Size, AdwordsUserListField.Status)
                    .orderAscBy(AdwordsUserListField.Id)
                    .offset(offset)
                    .limit(PAGE_SIZE)
                    .build();
        try {
            UserListPage page;
            do{
                page = userListService.get(selector);
                UserList[] userLists = page.getEntries();
                if(userLists != null && userLists.length > 0){
                    for(UserList ul : userLists){
                        if(audienceId.equalsIgnoreCase(ul.getId().toString())){
                            userList = ul;
                            break;
                        }
                    }
                }
                offset += PAGE_SIZE;
                selector = builder.increaseOffsetBy(PAGE_SIZE).build();
            }while (offset < page.getTotalNumEntries() && userList == null);
        } catch (RemoteException e) {
            log.error("fail to get user list [{}]", audienceId, e);
        }
    }

    private void mutateMembers(List<String> data, Operator operator) throws RemoteException {
        MutateMembersOperation operation = new MutateMembersOperation();
        MutateMembersOperand operand = new MutateMembersOperand();
        operand.setUserListId(userList.getId());

        List<Member> members = new ArrayList<>(data.size());
        for(String email : data){
            Member member = new Member();
            member.setHashedEmail(getHashedEmail(email));
            members.add(member);
        }
        operand.setMembersList(members.toArray(new Member[members.size()]));
        operation.setOperand(operand);
        operation.setOperator(operator);

        MutateMembersReturnValue result = userListService.mutateMembers(
                new MutateMembersOperation[]{operation}
        );

        UserList[] userListResult = result.getUserLists();
        String message = String.format("[%s], [%s] members %s in audience [%s][%s], upload status [%s], [%s] records found from csv",
                new SimpleDateFormat("yyyyMMdd").format(now().toDate()),
                members.size(), operator.getValue(), userList.getId(), userList.getName(),
                ((CrmBasedUserList) userListResult[0]).getDataUploadResult().getUploadStatus().getValue(), data.size());
        log.info("upload result : {}", message);
        if (Operator.ADD == operator) {
            addNotifyMessage(message);
        }
    }

May I know what are the Google Ads API I should use to achieve the same objectives?

Please let me know if the full listing of the codes is needed.

Thank you,
Derek

derek

unread,
Nov 21, 2022, 3:47:24 AM11/21/22
to Google Ads API and AdWords API Forum
The getUserList method is to select a list of  List ID and find a match with the passed in id.

May I know which library or query I can use to get this list of List ID?

This is the List ID I am referring to,

LIST_ID.PNG

As for the upload of the user list (mutateMembers method), it is to upload a list containing
Email Address, Country Code, First Name, Last Name, Phone, Zip
to the List ID.

May I know which library I should use to update or add the list to the List ID?

Thank you,
Derek

Google Ads API Forum Advisor

unread,
Nov 21, 2022, 5:51:18 AM11/21/22
to d3r...@gmail.com, adwor...@googlegroups.com

Hi Derek,

Thanks for reaching out to the Google Ads API Forum.

For you to migrate, you may refer to this guide for how to migrate from building user lists with AdwordsUserListService in the AdWords API to using UserDataService in the Google Ads API in order to sync Customer Match data. For more information on the migrating AdWords API Services to Google Ads API Services, you may refer to this page.

Also, for you to get user_list.id, you may use this code example for reporting by issuing the following query with GoogleAdsService.searchStream:

 

SELECT

  user_list.id, user_list.name

       user_list.resource_name, user_list.type 

FROM user_list

 

With this, you may consider updating your GAQL in the above provided example. In addition, to create a user list (a.k.a. audience) and uploads members to populate the list, you may refer to this code example in the Java client library.

Let us know if you have any followup questions.

Regards,

Google Logo
Yasar
Google Ads API Team
 


ref:_00D1U1174p._5004Q2gR1JZ:ref

derek

unread,
Nov 27, 2022, 10:35:58 PM11/27/22
to Google Ads API and AdWords API Forum
Hi

I followed the code example to create query with GoogleAdsService.searchStream: but encountered the following exception

Nov 28, 2022 11:21:58 AM io.grpc.internal.ManagedChannelImpl$2 uncaughtException
SEVERE: [Channel<1>: (googleads.googleapis.com:443)] Uncaught exception in the SynchronizationContext. Panic!
java.lang.IllegalStateException: Could not find policy 'pick_first'. Make sure its implementation is either registered to LoadBalancerRegistry or included in META-INF/services/io.grpc.LoadBalancerProvider from your jar files.

This is the code snippet of the method that does the query,

    private void getUserList(){
        log.info("get user list [{}]", audienceId);
        int offset = 0;
        userList = null;

        //String query = "SELECT user_list.id FROM user_list";

    try (GoogleAdsServiceClient googleAdsServiceClient =
        googleAdsClient.getLatestVersion().createGoogleAdsServiceClient()) {

        String query = "SELECT user_list.id FROM user_list";

        // Constructs the SearchGoogleAdsStreamRequest.
        SearchGoogleAdsStreamRequest request =
          SearchGoogleAdsStreamRequest.newBuilder()
              .setCustomerId(Long.toString(CUSTOMER_ID))
              .setQuery(query)
              .build();

        // Creates and issues a search Google Ads stream request that will retrieve all of the
        // requested field values for the keyword.
        ServerStream<SearchGoogleAdsStreamResponse> stream =
          googleAdsServiceClient.searchStreamCallable().call(request);

        // Iterates through the results in the stream response and prints all of the requested
        // field values for the keyword in each row.
        for (SearchGoogleAdsStreamResponse response : stream) {
          for (GoogleAdsRow googleAdsRow : response.getResultsList()) {
             System.out.printf("user list id = ", googleAdsRow.getUserList().getId());
          }
        }
    }
    }

I checked in the google-ads-java on giithub and followed the recommended workaround mentioned in this thread https://github.com/grpc/grpc-java/issues/5493#issuecomment-479156985 but I still get the same exception.
I have raised a question on this exception in github since last week but yet to get any feedback.

Attached is the log with the exception messages.

May I know how can I resolved this exception?
cron.20221128.log

Google Ads API Forum Advisor

unread,
Nov 28, 2022, 8:42:10 AM11/28/22
to d3r...@gmail.com, adwor...@googlegroups.com

Hi Derek,

Thanks for getting back to us.

I can see that you getting error with following:



"] Uncaught exception in the SynchronizationContext. Panic!

java.lang.IllegalStateException: Could not find policy 'pick_first'. Make sure its implementation is either registered to LoadBalancerRegistry or included in META-INF/services/io.grpc.LoadBalancerProvider from your jar files."


Also, as per your research, you already found the same issue filed on the GitHub issue tracker here, then it is more related to the client library concern. However, if you already have created a new issue with Issue tracker and didn’t get any response yet, then I would recommend you to wait for their reply so they provide further assistance in your concern. 

In the meantime, you may also use the Google Ads API REST API calls to get the user_list.id. For the REST, you may use the GoogleAdsService's search / searchStream method as an example provided here. You may also refer to our Query Cookbook guide which contains many reporting samples that correspond to some of the default Google Ads screens. Following are the two endpoints to fetch the objects from Google Ads:

search

POST /v12/customers/{customerId}/googleAds:search

Returns all rows that match the search query.

searchStream

POST /v12/customers/{customerId}/googleAds:searchStream

Returns all rows that match the search stream query.

derek

unread,
Nov 28, 2022, 9:51:20 PM11/28/22
to Google Ads API and AdWords API Forum
Hi

Will explore the REST API option.

Which REST API end points can I use to upload a list containing
Email Address, Country Code, First Name, Last Name, Phone, Zip
to a user list id?

Google Ads API Forum Advisor

unread,
Nov 29, 2022, 1:30:54 AM11/29/22
to d3r...@gmail.com, adwor...@googlegroups.com
Hi Derek,

This is Carmela from the Google Ads API support team as well.

Moving forward, as for the REST API endpoints, you may use this REST API link that you can use. Also, please also see this Userdata which is holding user identifiers and attributes. In addition, this UserIdentifier which you can use for constructing the "Email Address, Country Code, First Name, Last Name, Phone, Zip".

Let us know if this is what you're looking for.

Regards,
Google Logo
Carmela
Google Ads API Team
 


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