本文介绍了获取 MCC 帐户列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

过去两周我一直在努力使用 Google Ads Api 获取 MCC 帐户,但我无法实现我想要的.

I have been struggling with the Google Ads Api to get the MCC Accounts for the last two weeks but I am unable to achieve what I want.

我已经弄清楚了 App.Config

I have the App.Config figured out

<GoogleAdsApi>
    <!-- API-specific settings -->
    <add key="DeveloperToken" value="XXXXXXX"/>

    <!-- OAuth2 settings -->
    <add key="AuthorizationMethod" value="OAuth2" />
    <add key = "OAuth2ClientId" value = "XXXXXXX.apps.googleusercontent.com" />
    <add key = "OAuth2ClientSecret" value = " XXXXXXX  " />
    <add key = "OAuth2Mode" value="APPLICATION"/>
    <add key = "OAuth2RefreshToken" value = "1//0gd2 XXXXXXX  " />
</GoogleAdsApi>

这是我目前正在使用的代码

This is the code that I am currently working with

Public Sub GetMCCAccounts(ByVal client As GoogleAdsClient)
    Dim customerService As CustomerServiceClient = client.GetService(Services.V8.CustomerService)
    Dim customerResourceNames As String() = customerService.ListAccessibleCustomers()

    For Each customerResourceName As String In customerResourceNames
        Dim ManagerCustomerId = customerResourceName.Substring(customerResourceName.IndexOf("/") + 1)
        TextBox1.AppendText(vbCrLf & ManagerCustomerId)
    Next
End Sub

我没有得到正确的结果.我希望的 MCC 帐户没有出现在输出中.我得到不同的帐号.我错过了什么?

I am not getting the correct results. The MCC accounts that I was hoping for do not appear in the output. I am getting different account numbers. What am I missing?

预期的 MCC 帐户

我正在寻找这 10 个 MCC 帐户.

I am looking for these 10 MCC accounts.

子帐号设置概览

输出

我得到了这 16 个帐号.

I am getting these 16 account numbers.

64xxxxxxxx
71xxxxxxxx
10xxxxxxxx
88xxxxxxxx
32xxxxxxxx
58xxxxxxxx
31xxxxxxxx
73xxxxxxxx
98xxxxxxxx
22xxxxxxxx
48xxxxxxxx
37xxxxxxxx
98xxxxxxxx
94xxxxxxxx
88xxxxxxxx
43xxxxxxxx

推荐答案

熬夜终于破解了!

这终于给了我我想要的 MCC 帐户.

This finally gave me the MCC accounts that I wanted.

Imports Google.Ads.GoogleAds.Lib
Imports Google.Ads.GoogleAds.V8.Services
Imports Google.Ads.GoogleAds
Imports Google.Ads.GoogleAds.V8.Resources
Imports Google.Api.Gax
Imports Google.Apis

Public Class GoogleAdsCode
    Private Const PAGE_SIZE As Integer = 1000

    '~~> Get MCC Accounts
    Public Shared Function GetMCCAccounts(MgrId As Long?) As List(Of String)
        Dim googleAdsClient As New GoogleAdsClient
        Dim googleAdsServiceClient As GoogleAdsServiceClient = googleAdsClient.GetService(Services.V8.GoogleAdsService)
        Dim customerServiceClient As CustomerServiceClient = googleAdsClient.GetService(Services.V8.CustomerService)
        Dim seedCustomerIds As New List(Of Long)
        Dim MgrList As New List(Of String)

        seedCustomerIds.Add(MgrId.Value)

        Const query As String = "SELECT
                                    customer_client.client_customer,
                                    customer_client.level,
                                    customer_client.manager,
                                    customer_client.descriptive_name,
                                    customer_client.currency_code,
                                    customer_client.time_zone,
                                    customer_client.id
                                FROM customer_client
                                WHERE customer_client.level <= 1"
        Dim customerIdsToChildAccounts As Dictionary(Of Long, List(Of CustomerClient)) = New Dictionary(Of Long, List(Of CustomerClient))()

        For Each seedCustomerId As Long In seedCustomerIds
            Dim unprocessedCustomerIds As Queue(Of Long) = New Queue(Of Long)()
            unprocessedCustomerIds.Enqueue(seedCustomerId)
            Dim rootCustomerClient As CustomerClient = Nothing

            While unprocessedCustomerIds.Count > 0
                MgrId = unprocessedCustomerIds.Dequeue()
                Dim response As PagedEnumerable(Of SearchGoogleAdsResponse, GoogleAdsRow) = googleAdsServiceClient.Search(MgrId.ToString(), query, pageSize:=PAGE_SIZE)

                For Each googleAdsRow As GoogleAdsRow In response
                    Dim customerClient As CustomerClient = googleAdsRow.CustomerClient
                    If customerClient.ToString.Contains("MCC") Then MgrList.Add(customerClient.Id & " (" & customerClient.DescriptiveName & ")")
                Next
            End While
        Next

        Return MgrList
    End Function
End Class

这篇关于获取 MCC 帐户列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-01 06:10