Google api 如何获取adwords帐户客户id以将其链接到MCC帐户?
我想通过我的web应用程序上的Google Adwords API将Adwords帐户添加到MCC帐户。 我想我只需要添加一个 问题是我不知道如何获取clientCustomerId。 我认为通过在我的应用程序上使用匹配范围通过OAuth2对用户进行身份验证,我可以以某种方式获得他们的clientCustomerId,但我找不到它Google api 如何获取adwords帐户客户id以将其链接到MCC帐户?,google-api,google-ads-api,Google Api,Google Ads Api,我想通过我的web应用程序上的Google Adwords API将Adwords帐户添加到MCC帐户。 我想我只需要添加一个 问题是我不知道如何获取clientCustomerId。 我认为通过在我的应用程序上使用匹配范围通过OAuth2对用户进行身份验证,我可以以某种方式获得他们的clientCustomerId,但我找不到它 提前感谢您的帮助 根据您与George的上述交流,我想知道您是否真的想将AdWords帐户添加到您的MCC中 AdWords帐户所有者之间存在差异 授权您的应用程序访
提前感谢您的帮助 根据您与George的上述交流,我想知道您是否真的想将AdWords帐户添加到您的MCC中 AdWords帐户所有者之间存在差异
另一方面,如果这是一个web应用程序,而您只希望用户能够使用OAuth2进行授权,那么您应该遵循此操作。在这里,访问此链接到Google Adwords库 创建新用户后
$user = new AdWordsUser(); // with your API creds using OAUTH
GetAccountHierarchyExample(AdWordsUser $user) //found in link
只需运行函数。它将列出您所有的托管子帐户。您可以通过运行下一个代码来获取客户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并询问他的凭据。以下是您可以向客户获取的代码
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;
}
}
公共客户[]GetAllManagerClientsList(字符串授权代码)
{
字符串baseURL=_configuration.GetValue(“URL:SiteURL”);
AdsOAuthProviderForApplications oAuth2Provider=(user.OAuthProvider作为AdsOAuthProviderForApplications);
oAuth2Provider.Config.OAuth2RedirectUri=baseURL+“/google auth callback”;
oAuth2Provider.FetchAccessandFreshTokens(授权代码);
//获取客户ID
user.Config.OAuth2AccessToken=oAuth2Provider.Config.OAuth2AccessToken;
user.Config.OAuth2RefreshToken=oAuth2Provider.Config.OAuth2RefreshToken;
//存储在缓存中
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();
}
其他的
{
返回null;
}
}
对不起,我有点困惑。你想在哪里做这件事?您是在MCC中添加帐户,还是正在编码?我正在应用程序中进行编码,因此希望链接到应用程序MCC帐户的用户只需登录Google即可。谢谢您的帮助。如果我使用CustomerService,我只获得MCC帐户。基本上,我只想让我的web应用程序上的用户以一种方便的方式将他们的AdWords帐户链接到我的MCC帐户(这是您的bulletpoint 2.)。如何获取某人的10位AdWords客户ID?我想我可以先打电话,然后登录申请表。(你的要点1)。抱歉,如果这听起来令人困惑。您要链接的帐户当前是否由其他MCC管理?不。可能是,但我们假设不是。因此尝试过这样做,但它要求我提供客户Id来执行此操作。。。