How to GetUserList using Googld ads api ?

92 views
Skip to first unread message

IntegrationDeveloper

unread,
Mar 19, 2019, 3:17:40 PM3/19/19
to AdWords API and Google Ads API Forum
Hi 

    public long LookAudienceIdUsingName(string name)
    {
      AdwordsUserListService userListService =
        (AdwordsUserListService)_user.GetService(
          AdWordsService.v201809.AdwordsUserListService);

      string query = $"SELECT Id, Name, Status, AccountUserListStatus Where Name = '{name}' ORDER BY Id Desc";
      int offset = 0;
      int pageSize = 1;
      UserListPage page = new UserListPage();

      string queryWithPaging = $"{query} LIMIT {offset}, {pageSize}";
      page = userListService.query(queryWithPaging);

      foreach (UserList userList in page.entries)
        return page.entries[0].id;

      return 0;
    }

The above is my C# code to get an audience Id calling AdWords API - this works fine no problem. 

I'm now migrating our integration to Google Ads API. Can you please provide a sample code that do the same as the above ? I couldn't find one.

Thanks.
Sarah

googleadsapi...@google.com

unread,
Mar 20, 2019, 2:32:25 AM3/20/19
to AdWords API and Google Ads API Forum
Hi Sarah,

You can retrieve the UserList Ids by using the UserListService.GetUserList  and get UserList.id. My apologies as there are no sample codes available right now that I can provide. However, you may refer to the GetCampaigns.cs guide on how to use the get operation.

Regards,
Dannison
Google Ads API Team


=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
    http://googleadsdeveloper.blogspot.com/search/label/adwords_api
    https://developers.google.com/adwords/api/community/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

Was your question answered? Please rate your experience with us by taking a short survey.
If not -- reply to this email and tell us what else we can do to help.

Take Survey

Also find us on our blog and discussion group:
http://googleadsdeveloper.blogspot.com/search/label/adwords_api
https://developers.google.com/adwords/api/community/

--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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 adwor...@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscribe@googlegroups.com
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 adwords-api+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/adwords-api.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-api/a4dcfac3-42dc-4a42-9fc5-86b744b44390%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sarah

unread,
Mar 20, 2019, 8:04:39 AM3/20/19
to AdWords API and Google Ads API Forum
Hi Dannison,

Referring to the GetCampaigns.cs, I've worked out the code below. I like the flexibility of using GoogleAdsService queries - https://developers.google.com/google-ads/api/docs/query/overview, which is more relevant to my project than using UserListService.

      GoogleAdsServiceClient googleAdsService = _adsClient.GetService(Services.V1.GoogleAdsService);
      string query = $@"SELECT user_list.id, user_list.name, user_list.membership_status FROM user_list  
                         WHERE user_list.name = '{audienceName}' 
                         ORDER BY user_list.id DESC ";

      SearchGoogleAdsRequest request = new SearchGoogleAdsRequest()
      {
        PageSize = PAGE_SIZE,
        Query = query,
        CustomerId = customerId.ToString()
      };
 
PagedEnumerable<SearchGoogleAdsResponse, GoogleAdsRow> searchPagedResponse = googleAdsService.Search(request);
return (long)searchPagedResponse.FirstOrDefault()?.UserList.Id;


Thanks very much for your help.


Best Regards
Sarah
Reply all
Reply to author
Forward
0 new messages