【问题标题】:Get a list of MCC Accounts获取 MCC 帐户列表
【发布时间】:2021-07-07 14:10:42
【问题描述】:

在过去的两周里,我一直在努力使用 Google Ads Api 来获得 MCC Accounts,但我无法实现我想要的。

我已经弄清楚了 App.Config

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

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

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 帐户没有出现在输出中。我收到不同的帐号。我错过了什么?

预期的 MCC 帐户

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

子账户设置概览

输出

我正在获取这 16 个帐号。

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

【问题讨论】:

    标签: vb.net google-ads-api


    【解决方案1】:

    熬夜后,我终于成功破解了!

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

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多