ユーザー アクセスの招待の管理

Google 広告管理者は、Google 広告アカウントへのユーザー アクセスの招待を管理できます。

ユーザーを招待する

Google 広告アカウントへのアクセス権を管理する一環として、新しいユーザーに招待メールを送信することができます。それには、CustomerUserAccessInvitationServiceMutateCustomerUserAccessInvitation メソッドを使用して新しい CustomerUserAccessInvitation を作成します。招待を受け取ったユーザーは、招待を手動で承諾する必要があります。ユーザーが予備のメールアドレスを使用して招待を受諾することもできます。

次のコード スニペットは、招待状を送信する方法を示しています。

Java

// Constructs an access invitation.
CustomerUserAccessInvitation invitation =
    CustomerUserAccessInvitation.newBuilder()
        .setEmailAddress(emailAddress)
        .setAccessRole(accessRole)
        .build();

// Constructs an operation to send the invitation.
CustomerUserAccessInvitationOperation operation =
    CustomerUserAccessInvitationOperation.newBuilder().setCreate(invitation).build();

// Creates a CustomerUserAccessInvitationServiceClient.
try (CustomerUserAccessInvitationServiceClient client =
    googleAdsClient.getLatestVersion().createCustomerUserAccessInvitationServiceClient()) {
  // Issues the request.
  MutateCustomerUserAccessInvitationResponse response =
      client.mutateCustomerUserAccessInvitation(String.valueOf(customerId), operation);

  // Prints some information about the result.
  System.out.printf(
      "Customer user access invitation was sent for customerId = "
          + "%d to email address = '%s' and access role = '%s'. The invitation resource "
          + "name is '%s'.%n",
      customerId, emailAddress, accessRole, response.getResult().getResourceName());
}
      

C#

MutateCustomerUserAccessInvitationRequest invitationRequest =
    new MutateCustomerUserAccessInvitationRequest()
    {
        CustomerId = customerId.ToString(),
        Operation = new CustomerUserAccessInvitationOperation()
        {
            Create = new CustomerUserAccessInvitation()
            {
                EmailAddress = emailAddress,
                AccessRole = accessRole
            },
        }
    };
try
{
    var response = service.MutateCustomerUserAccessInvitation(invitationRequest);

    Console.WriteLine("Customer user access invitation was sent for customerId = " +
        "{0} to email address = {1} and access role = {2}. The invitation resource " +
        "name is {3}.", customerId, emailAddress, accessRole,
        response.Result.ResourceName);
}
catch (GoogleAdsException e)
{
    Console.WriteLine("Failure:");
    Console.WriteLine($"Message: {e.Message}");
    Console.WriteLine($"Failure: {e.Failure}");
    Console.WriteLine($"Request ID: {e.RequestId}");
    throw;
}
      

PHP

// Creates a customer user access invitation.
$customerUserAccessInvitation = new CustomerUserAccessInvitation([
    'email_address' =>  $emailAddress,
    'access_role' => AccessRole::value($accessRole)
]);

// Creates a customer user access invitation operation.
$customerUserAccessInvitationOperation = new CustomerUserAccessInvitationOperation();
$customerUserAccessInvitationOperation->setCreate($customerUserAccessInvitation);

// Issues a mutate request to send the customer user access invitation and prints its
// information.
$customerUserAccessInvitationServiceClient =
    $googleAdsClient->getCustomerUserAccessInvitationServiceClient();
$response = $customerUserAccessInvitationServiceClient->mutateCustomerUserAccessInvitation(
    $customerId,
    $customerUserAccessInvitationOperation
);
printf(
    "Customer user access invitation with resource name '%s' was sent from customer "
    . "ID %d to email address '%s' with access role '%s'.%s",
    $response->getResult()->getResourceName(),
    $customerId,
    $emailAddress,
    $accessRole,
    PHP_EOL
);
      

Python

invitation_operation = client.get_type(
    "CustomerUserAccessInvitationOperation"
)
invitation = invitation_operation.create
invitation.email_address = email_address
invitation.access_role = client.enums.AccessRoleEnum[access_role].value

response = service.mutate_customer_user_access_invitation(
    customer_id=customer_id, operation=invitation_operation
)
print(
    "Customer user access invitation was sent for "
    f"customer ID: '{customer_id}', "
    f"email address {email_address}, and "
    f"access role {access_role}. The invitation resource name is: "
    f"{response.result.resource_name}"
)
      

Ruby

operation = client.operation.create_resource.customer_user_access_invitation do |inv|
  inv.email_address = email_address
  inv.access_role = access_role
end

# Issues a mutate request to get the response.
response = client.service.customer_user_access_invitation.mutate_customer_user_access_invitation(
  customer_id: customer_id,
  operation: operation,
)

# Prints out information of the created invitation.
puts "Customer user access invitation was sent for customerId = #{customer_id} " \
  "email address = '#{email_address}', " \
  "access role = '#{access_role}'."
      

Perl

sub invite_user_with_access_role {
  my ($api_client, $customer_id, $email_address, $access_role) = @_;

  # Create the user access invitation.
  my $user_access_invitation =
    Google::Ads::GoogleAds::V11::Resources::CustomerUserAccessInvitation->new({
      emailAddress => $email_address,
      accessRole   => $access_role
    });

  # Create the user access invitation operation.
  my $invitation_operation =
    Google::Ads::GoogleAds::V11::Services::CustomerUserAccessInvitationService::CustomerUserAccessInvitationOperation
    ->new({create => $user_access_invitation});

  # Send the user access invitation.
  my $invitation_response =
    $api_client->CustomerUserAccessInvitationService()->mutate({
      customerId => $customer_id,
      operation  => $invitation_operation
    });

  printf "Customer user access invitation was sent for customerId = %d " .
    "to email address = '%s' and access role = '%s'. " .
    "The invitation resource name is '%s'.\n",
    $customer_id, $email_address, $access_role,
    $invitation_response->{result}{resourceName};

  return 1;
}
      

招待状を取り消す

招待を取り消すには、CustomerUserAccessInvitationServiceMutateCustomerUserAccessInvitation メソッドを使用して CustomerUserAccessInvitation を削除します。

ユーザーの招待を取得する

保留中のユーザーの招待のリストを取得するには、Google 広告クエリ言語ステートメントを作成して、顧客 ID に関連付けられたすべての CustomerUserAccessInvitation エンティティに対してクエリを実行します。一般的なクエリは次のとおりです。

SELECT
    customer_user_access_invitation.invitation_id,
    customer_user_access_invitation.email_address,
    customer_user_access_invitation.access_role,
    customer_user_access_invitation.invitation_status,
    customer_user_access_invitation.creation_date_time
FROM
    customer_user_access_invitation

フィルタ条件を追加して、招待のサブセットを取得できます。たとえば、一般的なユースケースでは、保留中のユーザーの招待のリストを取得します。これを行うには、customer_user_access_invitation.invitation_status = PENDING でフィルタリングします。

Java

String query =
    "SELECT"
        + "  customer_user_access_invitation.invitation_id, "
        + "  customer_user_access_invitation.email_address, "
        + "  customer_user_access_invitation.access_role, "
        + "  customer_user_access_invitation.creation_date_time "
        + "FROM "
        + "  customer_user_access_invitation "
        + "WHERE "
        + "  customer_user_access_invitation.invitation_status = PENDING";
SearchPagedResponse response = client.search(String.valueOf(customerId), query);
for (GoogleAdsRow row : response.iterateAll()) {
  System.out.printf(
      "A pending invitation with invitation ID = %d, "
          + "email address = '%s', access role = '%s' and created on %s"
          + " was found.%n",
      row.getCustomerUserAccessInvitation().getInvitationId(),
      row.getCustomerUserAccessInvitation().getEmailAddress(),
      row.getCustomerUserAccessInvitation().getAccessRole(),
      row.getCustomerUserAccessInvitation().getCreationDateTime());
}
      

C#

// Create the search query.
string query =
    @"SELECT
        customer_user_access_invitation.invitation_id,
        customer_user_access_invitation.email_address,
        customer_user_access_invitation.access_role,
        customer_user_access_invitation.creation_date_time
      FROM
        customer_user_access_invitation
      WHERE
        customer_user_access_invitation.invitation_status=PENDING";

try
{
    // Issue a search request.
    googleAdsService.SearchStream(customerId.ToString(), query,
        delegate (SearchGoogleAdsStreamResponse resp)
        {
            foreach (GoogleAdsRow googleAdsRow in resp.Results)
            {
                Console.WriteLine("A pending invitation with invitation ID = {0}, " +
                    "email address = '{1}', access role = '{2}' and created on {3}" +
                    " was found.",
                    googleAdsRow.CustomerUserAccessInvitation.InvitationId,
                    googleAdsRow.CustomerUserAccessInvitation.EmailAddress,
                    googleAdsRow.CustomerUserAccessInvitation.AccessRole,
                    googleAdsRow.CustomerUserAccessInvitation.CreationDateTime
                );
            }
        }
    );
}
catch (GoogleAdsException e)
{
    Console.WriteLine("Failure:");
    Console.WriteLine($"Message: {e.Message}");
    Console.WriteLine($"Failure: {e.Failure}");
    Console.WriteLine($"Request ID: {e.RequestId}");
    throw;
}
      

PHP

// Creates a query to find pending customer user access invitations.
$query = 'SELECT customer_user_access_invitation.invitation_id, '
    . 'customer_user_access_invitation.email_address, '
    . 'customer_user_access_invitation.access_role, '
    . 'customer_user_access_invitation.creation_date_time '
    . 'FROM customer_user_access_invitation '
    . 'WHERE customer_user_access_invitation.invitation_status = PENDING';

// Issues a search stream request.
$response = $googleAdsServiceClient->searchStream($customerId, $query);

// Iterates over all rows and prints the requested field values for the customer user
// access invitation in each row.
foreach ($response->iterateAllElements() as $googleAdsRow) {
    /** @var GoogleAdsRow $googleAdsRow */
    printf(
        "A pending invitation with invitation ID %d, email address '%s', access role "
        . "'%s' created on '%s' was found.%s",
        $googleAdsRow->getCustomerUserAccessInvitation()->getInvitationId(),
        $googleAdsRow->getCustomerUserAccessInvitation()->getEmailAddress(),
        AccessRole::name($googleAdsRow->getCustomerUserAccessInvitation()->getAccessRole()),
        $googleAdsRow->getCustomerUserAccessInvitation()->getCreationDateTime(),
        PHP_EOL
    );
}
      

Python

query = """
    SELECT
      customer_user_access_invitation.invitation_id,
      customer_user_access_invitation.email_address,
      customer_user_access_invitation.access_role,
      customer_user_access_invitation.creation_date_time
    FROM customer_user_access_invitation
    WHERE customer_user_access_invitation.invitation_status = PENDING"""

stream = googleads_service.search_stream(
    customer_id=customer_id, query=query
)
for batch in stream:
    for row in batch.results:
        invite = row.customer_user_access_invitation
        print(
            "A pending invitation with "
            f"invitation ID: '{invite.invitation_id}', "
            f"email address: {invite.email_address}, "
            f"access role: {invite.access_role}, and "
            f"created on: {invite.creation_date_time} was found."
        )


      

Ruby

query = <<~QUERY
  SELECT
    customer_user_access_invitation.invitation_id,
    customer_user_access_invitation.email_address,
    customer_user_access_invitation.access_role,
    customer_user_access_invitation.creation_date_time
  FROM
    customer_user_access_invitation
  WHERE
    customer_user_access_invitation.invitation_status = PENDING
QUERY

# Execute the query to fetch results from the API.
response = client.service.google_ads.search(
  customer_id: customer_id,
  query: query,
  page_size: PAGE_SIZE
)

# Process the results and output changes.
response.each do |row|
  invitation = row.customer_user_access_invitation
  puts "A pending invitation with " \
    "invitation ID = #{invitation.invitation_id}, " \
    "email address = '#{invitation.email_address}', " \
    "access role = '#{invitation.access_role}' " \
    " and created on #{invitation.creation_date_time} was found."
end
      

Perl

sub get_pending_invitations {
  my ($api_client, $customer_id) = @_;

  # Create a query that retrieves the pending invitations.
  my $search_query =
    "SELECT customer_user_access_invitation.invitation_id, " .
    "customer_user_access_invitation.email_address, " .
    "customer_user_access_invitation.access_role, " .
    "customer_user_access_invitation.creation_date_time " .
    "FROM customer_user_access_invitation " .
    "WHERE customer_user_access_invitation.invitation_status= 'PENDING'";

  # Create a search Google Ads stream request that will retrieve the pending
  # invitations.
  my $search_stream_request =
    Google::Ads::GoogleAds::V11::Services::GoogleAdsService::SearchGoogleAdsStreamRequest
    ->new({
      customerId => $customer_id,
      query      => $search_query,
    });

  # Get the GoogleAdsService.
  my $google_ads_service = $api_client->GoogleAdsService();

  my $search_stream_handler =
    Google::Ads::GoogleAds::Utils::SearchStreamHandler->new({
      service => $google_ads_service,
      request => $search_stream_request
    });

  # Issue a search request and process the stream response to print the requested
  # field values for the pending invitation in each row.
  $search_stream_handler->process_contents(
    sub {
      my $google_ads_row    = shift;
      my $access_invitation = $google_ads_row->{customerUserAccessInvitation};

      printf
        "A pending invitation with invitation ID = %d, email address = '%s', "
        . "access role = '%s' and created on %s was found.\n",
        $access_invitation->{invitationId},
        $access_invitation->{emailAddress}, $access_invitation->{accessRole},
        $access_invitation->{creationDateTime};
    });

  return 1;
}