Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
486 views
in Technique[技术] by (71.8m points)

ads - Google adwords customers API is not returning customers list?

I have this following code to fetch all list of ads clients comes under a Ads manager account, I am using manager credentials to get list of clients.

public Customer[] GetAllManagerClientsList(string currentUserEmail, string authorizationCode)
    {
        string baseURL = _configuration.GetValue<string>("URL:SiteURL");
        var currentUser = _userRepository.GetIntegratedAppsDetailByEmail(currentUserEmail);
        AdsOAuthProviderForApplications oAuth2Provider = (user.OAuthProvider as AdsOAuthProviderForApplications);
        oAuth2Provider.Config.OAuth2RedirectUri = baseURL + "/google-auth-callback";

        oAuth2Provider.FetchAccessAndRefreshTokens(authorizationCode);

        //Get customerID
        user.Config.OAuth2AccessToken = oAuth2Provider.Config.OAuth2AccessToken;
        user.Config.OAuth2RefreshToken = oAuth2Provider.Config.OAuth2RefreshToken;
        CustomerService customerService = (CustomerService)user.GetService(AdWordsService.v201809.CustomerService);
        var customersList = customerService.getCustomers();

        var ClientCustomers = customersList != null && customersList.Length > 0 ? customersList.Where(c => c.canManageClients == false).ToList() : null;
        if (ClientCustomers.Count() > 0)
        {
            return ClientCustomers.ToArray();
        }
        else
        {
            return null;
        }
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Faruk What is your question? What are you seeing? It's not really clear what the issue is.

Edit: You tagged this with Google-Ads-API, that's the old API. My code below is for the new Google Ads API but might point you in the right direction if you need to use the older one.

You're using the correct service, just not the correct method. You need to use the list_accessible_customers() method:

def get_mccs_and_direct_admin_only_accounts(client):
customer_service = client.get_service('CustomerService', version='v6')

try:
    accessible_customers = customer_service.list_accessible_customers()

    resource_names = accessible_customers.resource_names
    for resource_name in resource_names:
        print('Customer resource name: "%s"' % resource_name)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...