如何获取adwords帐户客户端ID以将其链接到MCC帐户?

时间:2014-05-05 02:29:16

标签: google-api google-adwords

我想在我的网络应用程序上通过Google Adwords API向您的MCC帐户添加Adwords帐户。 我想我只需要添加ManagedCustomerLink

问题是我不知道如何获得 clientCustomerId 。 我想通过OAuth2在我的应用程序上使用匹配范围对用户进行身份验证,我可以以某种方式获取他们的 clientCustomerId ,但我找不到它。

提前感谢您的帮助!

4 个答案:

答案 0 :(得分:1)

您可以通过运行下一个代码来获取客户端客户ID:

CustomerServiceInterface customerService = adWordsServices.get(session, CustomerServiceInterface.class);
Customer[] customers;
try {
    customers = customerService.getCustomers();
    for (Customer customer : customers) {
        Long customerId = customer.getCustomerId();
        System.out.println(customerId);
    }
} catch (RemoteException e) {
    e.printStackTrace();
}

为了获得用户会话,您必须使用Oauth 2.0并询问他的凭据。

答案 1 :(得分:0)

根据阅读上述George Astonishing的交流,我想知道您是否真的想要将AdWords帐户添加到MCC。

AdWords帐户所有者

之间存在差异
  1. 授权您的应用访问其数据,vs
  2. 成为贵公司的客户,进行全面的AdWords管理。
  3. 如果此AdWords帐户属于贵公司的客户,并且您正在接管其帐户管理,则可以使用ManagedCustomerService将该帐户添加到您的MCC。您可以使用CustomerService获取该帐户的10位AdWords客户ID。

    另一方面,如果这是针对网络应用,并且您只希望用户能够使用OAuth2进行授权,那么您应该关注this guide

答案 2 :(得分:0)

在此处,请访问此Google Adwords图书馆链接

https://github.com/googleads/googleads-php-lib/blob/master/examples/AdWords/v201509/AccountManagement/GetAccountHierarchy.php

创建新用户后

   $user = new AdWordsUser(); // with your API creds using OAUTH       
   GetAccountHierarchyExample(AdWordsUser $user)  //found in link

只需运行该功能。它将列出您的所有托管子帐户。

答案 3 :(得分:-1)

这是您可以获取客户客户的代码

public Customer[] GetAllManagerClientsList(string authorizationCode)
        {
            string baseURL = _configuration.GetValue<string>("URL:SiteURL");
            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;
            //store in cache
            var chechedEntryOptions = new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromMinutes(5));


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