Google 広告のアクセスモデルについて

Google 広告アカウントには、Google 広告クライアント センター(MCC)アカウント Google 広告広告主アカウント(お客様アカウントまたはクライアント アカウントとも呼ばれます)の 2 種類があります。MCC アカウントでは、他の Google 広告 MCC アカウントや Google 広告広告主アカウントを管理できます。広告主アカウントをクライアント センター(MCC)アカウントにリンクすると、クライアント センター(MCC)アカウントを通じて広告主アカウントを管理できるようになります。リンクされた構造全体は、リーフレベルに広告主アカウントがある有向非巡回グラフです。

個々のユーザーまたはサービス アカウントに Google 広告アカウントへのアクセス権を付与できます。ユーザーに広告主アカウントへのアクセス権を付与する方法は 2 つあります。

  • 広告主様のアカウントに招待することで、そのアカウントへの直接アクセス権をユーザーに付与します。
  • そのアカウントにリンクされている MCC アカウントにユーザーを招待して、広告主アカウントへの間接的なアクセス権を付与します。MCC アカウントは、その下にリンクされているすべてのアカウントにアクセスできるため、ユーザーは広告主アカウントにアクセスできるようになります。

アカウントの管理にユーザーを招待する際に、ユーザーロールを割り当てることもできます。

次のアカウント階層を考えてみましょう。すべてのユーザーが標準アクセス権を持っているとします。

アカウント階層の図

次の表に、このアカウント構造の概要を示します。

ユーザー 直接アクセスできる 間接的にアクセスできる
U1、SA1 M1 M2、A1、A2、A3
U2 M2、M3 A1、A2、A3、A4
U3 A4  

ログイン用お客様 ID

ユーザーは複数のアカウント階層にアクセスできる場合があります。このような場合に API 呼び出しを行うときは、認証とアカウントのアクセスレベルを正しく判断するために使用するルート アカウントを指定する必要があります。これを行うには、API リクエストの一部として login-customer-id ヘッダーを指定します。

次の表では、前の例のアカウント階層を使用して、使用できるログイン顧客 ID と、呼び出し可能なアカウントの対応するリストを示します。

ユーザー 使用するログイン用お客様 ID API 呼び出しを行うアカウント
U1、SA1 M1 M1、M2、A1、A2、A3
U2 M2 M2、A1、A2、A3
U2 M3 M3、A1、A4
U3 A4 A4

呼び出し先の Google 広告アカウントにユーザーが直接アクセスできる場合は、login-customer-id ヘッダーの指定を省略できます。たとえば、U3 認証情報を使用して A4 に呼び出しを行う場合、Google 広告サーバーは顧客 ID(A4)からアクセスレベルを正しく判断できるため、login-customer-id ヘッダーを指定する必要はありません。

Google のクライアント ライブラリを使用している場合は、次の設定を使用して login-customer-id ヘッダーを指定します。

Java

ads.properties ファイルに次の設定を追加します。

api.googleads.loginCustomerId=INSERT_LOGIN_CUSTOMER_ID_HERE

C#

GoogleAdsConfig オブジェクトを初期化して GoogleAdsClient オブジェクトを作成するときに、次の設定を追加します。

GoogleAdsConfig config = new GoogleAdsConfig()
{
    ...
    LoginCustomerId = ******
};
GoogleAdsClient client = new GoogleAdsClient(config);

PHP

google_ads_php.ini ファイルに次の設定を追加します。

[GOOGLE_ADS]
loginCustomerId = "INSERT_LOGIN_CUSTOMER_ID_HERE"

Python

google-ads.yaml ファイルに次の設定を追加します。

login_customer_id: INSERT_LOGIN_CUSTOMER_ID_HERE

Ruby

google_ads_config.rb ファイルに次の設定を追加します。

Google::Ads::GoogleAds::Config.new do |c|
  c.login_customer_id = 'INSERT_LOGIN_CUSTOMER_ID_HERE'
end

このファイルを保存しているパスを渡して、GoogleAdsClient インスタンスを作成します。

client = Google::Ads::GoogleAds::GoogleAdsClient.new('path/to/google_ads_config.rb')

Perl

googleads.properties ファイルに次の設定を追加します。

loginCustomerId=INSERT_LOGIN_CUSTOMER_ID_HERE

curl

curl コマンドを実行するときに、次のコマンドライン引数を指定します。

-H "login-customer-id: LOGIN_CUSTOMER_ID"

CustomerService.ListAccessibleCustomers メソッドを使用して、ユーザーが直接アクセスできるアカウントのリストを取得できます。これらのアカウントは、login-customer-id ヘッダーの有効な値として使用できます。

Java

private void runExample(GoogleAdsClient client) {
  // Optional: Change credentials to use a different refresh token, to retrieve customers
  //           available for a specific user.
  //
  // UserCredentials credentials =
  //     UserCredentials.newBuilder()
  //         .setClientId("INSERT_OAUTH_CLIENT_ID")
  //         .setClientSecret("INSERT_OAUTH_CLIENT_SECRET")
  //         .setRefreshToken("INSERT_REFRESH_TOKEN")
  //         .build();
  //
  // client = client.toBuilder().setCredentials(credentials).build();

  try (CustomerServiceClient customerService =
      client.getLatestVersion().createCustomerServiceClient()) {
    ListAccessibleCustomersResponse response =
        customerService.listAccessibleCustomers(
            ListAccessibleCustomersRequest.newBuilder().build());

    System.out.printf("Total results: %d%n", response.getResourceNamesCount());

    for (String customerResourceName : response.getResourceNamesList()) {
      System.out.printf("Customer resource name: %s%n", customerResourceName);
    }
  }
}
      

C#

public void Run(GoogleAdsClient client)
{
    // Get the CustomerService.
    CustomerServiceClient customerService = client.GetService(Services.V21.CustomerService);

    try
    {
        // Retrieve the list of customer resources.
        string[] customerResourceNames = customerService.ListAccessibleCustomers();

        // Display the result.
        foreach (string customerResourceName in customerResourceNames)
        {
            Console.WriteLine(
                $"Found customer with resource name = '{customerResourceName}'.");
        }
    }
    catch (GoogleAdsException e)
    {
        Console.WriteLine("Failure:");
        Console.WriteLine($"Message: {e.Message}");
        Console.WriteLine($"Failure: {e.Failure}");
        Console.WriteLine($"Request ID: {e.RequestId}");
        throw;
    }
}
      

PHP

public static function runExample(GoogleAdsClient $googleAdsClient)
{
    $customerServiceClient = $googleAdsClient->getCustomerServiceClient();

    // Issues a request for listing all accessible customers.
    $accessibleCustomers =
        $customerServiceClient->listAccessibleCustomers(new ListAccessibleCustomersRequest());
    print 'Total results: ' . count($accessibleCustomers->getResourceNames()) . PHP_EOL;

    // Iterates over all accessible customers' resource names and prints them.
    foreach ($accessibleCustomers->getResourceNames() as $resourceName) {
        /** @var string $resourceName */
        printf("Customer resource name: '%s'%s", $resourceName, PHP_EOL);
    }
}
      

Python

def main(client: GoogleAdsClient) -> None:
    customer_service: CustomerServiceClient = client.get_service(
        "CustomerService"
    )

    accessible_customers: ListAccessibleCustomersResponse = (
        customer_service.list_accessible_customers()
    )
    result_total: int = len(accessible_customers.resource_names)
    print(f"Total results: {result_total}")

    resource_names: List[str] = accessible_customers.resource_names
    for resource_name in resource_names:  # resource_name is implicitly str
        print(f'Customer resource name: "{resource_name}"')
      

Ruby

def list_accessible_customers()
  # GoogleAdsClient will read a config file from
  # ENV['HOME']/google_ads_config.rb when called without parameters
  client = Google::Ads::GoogleAds::GoogleAdsClient.new

  accessible_customers = client.service.customer.list_accessible_customers().resource_names

  accessible_customers.each do |resource_name|
    puts "Customer resource name: #{resource_name}"
  end
end
      

Perl

sub list_accessible_customers {
  my ($api_client) = @_;

  my $list_accessible_customers_response =
    $api_client->CustomerService()->list_accessible_customers();

  printf "Total results: %d.\n",
    scalar @{$list_accessible_customers_response->{resourceNames}};

  foreach
    my $resource_name (@{$list_accessible_customers_response->{resourceNames}})
  {
    printf "Customer resource name: '%s'.\n", $resource_name;
  }

  return 1;
}
      

curl

# Returns the resource names of customers directly accessible by the user
# authenticating the call.
#
# Variables:
#   API_VERSION,
#   DEVELOPER_TOKEN,
#   OAUTH2_ACCESS_TOKEN:
#     See https://developers.google.com/google-ads/api/rest/auth#request_headers
#     for details.
#
curl -f --request GET \
"https://googleads.googleapis.com/v${API_VERSION}/customers:listAccessibleCustomers" \
--header "Content-Type: application/json" \
--header "developer-token: ${DEVELOPER_TOKEN}" \
--header "Authorization: Bearer ${OAUTH2_ACCESS_TOKEN}" \
      

ユーザーロール

Google Ads API には、独自のアクセスモデルが別途用意されているわけではなく、OAuth 2.0 スコープを別途使用して機能を制限することもありません。たとえば、Google Ads API では、読み取り専用オペレーションと読み書きオペレーションに同じスコープが使用されます。代わりに、Google Ads API は Google Ads がサポートする同じユーザーロールに従います。ユーザーロールがマネージャー レベルでアカウントに付与されると、そのロールは階層内のアカウントに継承されます。ユーザーが特定のアカウントに対して競合するロールを持っている場合、API リクエストで指定された login-customer-id アカウントによって正しいレベルが解決されます。

次の表は、前の例のアカウント階層を使用して、さまざまなユーザーロールをユーザーに付与した場合の効果を示しています。

ユーザー ユーザーロールが付与されました login-customer-id 有効なアクセスレベル
SA1 アカウント M1 の標準権限 M1 M1、M2、A1、A2、A3 の標準アクセス
U2 M2 の標準アクセス
M3 の読み取り専用アクセス
M2 M2、A1、A2、A3 の標準アクセス
U2 M2 の標準アクセス
M3 の読み取り専用アクセス
M3 M3、A1、A4 での読み取り専用アクセス