ทําความเข้าใจรูปแบบการเข้าถึง Google Ads

บัญชี Google Ads มี 2 ประเภท ได้แก่ บัญชีดูแลจัดการ Google Ads และ บัญชีผู้ลงโฆษณา Google Ads (หรือที่เรียกว่าบัญชีลูกค้า) บัญชีดูแลจัดการสามารถจัดการบัญชีดูแลจัดการ Google Ads อื่นๆ หรือบัญชีผู้ลงโฆษณา Google Ads ได้ คุณลิงก์บัญชีผู้ลงโฆษณากับบัญชีดูแลจัดการ แล้ว จัดการบัญชีผู้ลงโฆษณาผ่านบัญชีดูแลจัดการได้ โครงสร้างโดยรวมที่ลิงก์กันคือกราฟแบบมีทิศทางและไม่มีวงจรที่มีบัญชีผู้ลงโฆษณา ที่ระดับล่างสุด

คุณให้สิทธิ์เข้าถึงบัญชี Google Ads แก่ผู้ใช้แต่ละรายหรือบัญชีบริการได้ คุณให้สิทธิ์ผู้ใช้เข้าถึงบัญชีผู้ลงโฆษณาได้ 2 วิธีดังนี้

  • ให้สิทธิ์ผู้ใช้เข้าถึงบัญชีผู้ลงโฆษณาโดยตรงด้วยการเชิญ ผู้ใช้ให้เข้าถึงบัญชีดังกล่าว
  • ให้สิทธิ์ผู้ใช้เข้าถึงบัญชีผู้ลงโฆษณาโดยอ้อมด้วยการเชิญผู้ใช้ไปยังบัญชีดูแลจัดการที่ลิงก์กับบัญชีนั้น ผู้ใช้จะได้รับสิทธิ์เข้าถึงบัญชีผู้ลงโฆษณาเนื่องจาก บัญชีดูแลจัดการมีสิทธิ์เข้าถึงบัญชีทั้งหมดที่ลิงก์ภายใต้บัญชีดูแลจัดการ

นอกจากนี้ คุณยังมอบหมายบทบาทผู้ใช้ได้เมื่อเชิญผู้ใช้ให้จัดการบัญชี

ลองพิจารณาลำดับชั้นบัญชีต่อไปนี้ สมมติว่าผู้ใช้ทั้งหมดมีสิทธิ์เข้าถึงแบบมาตรฐาน

แผนภาพลำดับชั้นบัญชี

ตารางต่อไปนี้สรุปโครงสร้างบัญชีนี้

ผู้ใช้ มีสิทธิ์เข้าถึงโดยตรง มีสิทธิ์เข้าถึงโดยอ้อม
U1, SA1 M1 M2, A1, A2, A3
U2 M2, M3 A1, A2, A3, A4
U3 A4  

รหัสลูกค้าสำหรับการเข้าสู่ระบบ

ผู้ใช้อาจมีสิทธิ์เข้าถึงลําดับชั้นของบัญชีหลายรายการ เมื่อทำการเรียก API ในกรณีดังกล่าว คุณต้องระบุบัญชีรูทที่จะใช้เพื่อกำหนดระดับการให้สิทธิ์และการเข้าถึงบัญชีอย่างถูกต้อง โดยทำได้ด้วยการระบุส่วนหัว login-customer-id เป็นส่วนหนึ่งของคำขอ API

ตารางต่อไปนี้ใช้ลําดับชั้นบัญชีจากตัวอย่างก่อนหน้าเพื่อแสดงรหัสลูกค้าสําหรับการเข้าสู่ระบบที่คุณใช้ได้ และ รายการบัญชีที่เกี่ยวข้องซึ่งคุณเรียกใช้ได้

ผู้ใช้ เข้าสู่ระบบรหัสลูกค้าเพื่อใช้งาน บัญชีที่จะใช้เรียก API
U1, SA1 M1 M1, M2, A1, A2, A3
U2 M2 M2, A1, A2, A3
U2 M3 M3, A1, A4
U3 A4 A4

คุณข้ามการระบุส่วนหัว login-customer-id ได้หากผู้ใช้มีสิทธิ์เข้าถึงบัญชี Google Ads ที่คุณเรียกใช้โดยตรง เช่น คุณไม่จำเป็นต้องระบุส่วนหัว login-customer-id เมื่อใช้ข้อมูลเข้าสู่ระบบ U3 เพื่อ โทรไปยัง A4 เนื่องจากเซิร์ฟเวอร์ของ Google Ads สามารถกำหนดระดับการเข้าถึงจากรหัสลูกค้า (A4) ได้อย่างถูกต้อง

หากคุณใช้ไลบรารีของไคลเอ็นต์ของเรา ให้ใช้การตั้งค่าต่อไปนี้เพื่อระบุ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 รองรับ เมื่อมอบบทบาทผู้ใช้ให้กับ บัญชีที่ระดับผู้จัดการ บัญชีในลำดับชั้น จะรับช่วงบทบาทดังกล่าว หากผู้ใช้มีบทบาทที่ขัดแย้งกันในบัญชีหนึ่งๆ ระบบจะแก้ไขระดับที่ถูกต้องโดยใช้login-customer-idบัญชีที่ระบุในคำขอ API

ตารางต่อไปนี้ใช้ลําดับชั้นบัญชีจากตัวอย่างก่อนหน้าและแสดงผลของการให้บทบาทผู้ใช้ต่างๆ แก่ผู้ใช้

ผู้ใช้ บทบาทของผู้ใช้ที่ได้รับ 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