Quản lý quyền truy cập tài khoản Google Ads một cách hiệu quả

Quản lý quyền truy cập của người dùng là một yếu tố quan trọng trong việc vận hành tài khoản Google Ads hiệu quả, đảm bảo rằng chỉ những người có thẩm quyền mới có thể truy cập và thay đổi các cài đặt quan trọng. Google Ads cung cấp khả năng quản lý quyền truy cập thông qua API, giúp bạn dễ dàng kiểm tra, sửa đổi và quản lý quyền truy cập của người dùng trong tài khoản của mình. Trong bài viết này, chúng ta sẽ tìm hiểu cách sử dụng Google Ads API để truy vấn thông tin người dùng có quyền truy cập vào tài khoản và cách sửa đổi quyền truy cập của họ một cách hiệu quả. Đồng thời, hướng dẫn này sẽ cung cấp ví dụ minh hoạ mã sử dụng API Google Ads cho các ngôn ngữ lập trình phổ biến như Java, C#, PHP, Python, Ruby và Perl.

Là quản trị viên Google Ads, bạn có thể quản lý quyền truy cập của người dùng vào tài khoản của mình bằng cách sử dụng Google Ads Query Language (GAQL). Thông qua việc tạo truy vấn, bạn có thể truy xuất tất cả các thực thể CustomerUserAccess liên kết với một mã khách hàng cụ thể. Dưới đây là một ví dụ điển hình về truy vấn:

SELECT
customer_user_access.user_id,
customer_user_access.email_address,
customer_user_access.access_role,
customer_user_access.access_creation_date_time,
customer_user_access.inviter_user_email_address
FROM customer_user_access

Truy vấn này cho phép bạn liệt kê thông tin về người dùng có quyền truy cập, bao gồm mã định danh người dùng (user_id), địa chỉ email, vai trò truy cập (access_role), thời gian tạo quyền truy cập và địa chỉ email của người đã mời. Bên cạnh đó, bạn cũng có thể kiểm tra danh sách người dùng hiện có quyền truy cập vào tài khoản của mình, sửa đổi vai trò truy cập của họ hoặc thậm chí xoá bỏ quyền truy cập nếu cần. Hãy tìm hiểu thêm về các cấp độ quyền truy cập để đảm bảo việc quản lý tài khoản một cách tối ưu và bảo mật.

Dưới đây là ví dụ về mã minh họa cách chỉnh sửa vai trò truy cập của một người dùng trong Google Ads. Ví dụ này giả định rằng bạn đã xác định chính xác quyền truy cập của người dùng bằng cách chạy truy vấn để lấy thông tin từ CustomerUserAccess.

Mã minh họa:

// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// You may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.ads.googleads.examples.accountmanagement;

import com.beust.jcommander.Parameter;
import com.google.ads.googleads.examples.utils.ArgumentNames;
import com.google.ads.googleads.examples.utils.CodeSampleParams;
import com.google.ads.googleads.lib.GoogleAdsClient;
import com.google.ads.googleads.lib.utils.FieldMasks;
import com.google.ads.googleads.v17.enums.AccessRoleEnum.AccessRole;
import com.google.ads.googleads.v17.errors.GoogleAdsError;
import com.google.ads.googleads.v17.errors.GoogleAdsException;
import com.google.ads.googleads.v17.resources.CustomerUserAccess;
import com.google.ads.googleads.v17.services.CustomerUserAccessOperation;
import com.google.ads.googleads.v17.services.CustomerUserAccessServiceClient;
import com.google.ads.googleads.v17.services.GoogleAdsRow;
import com.google.ads.googleads.v17.services.GoogleAdsServiceClient;
import com.google.ads.googleads.v17.services.GoogleAdsServiceClient.SearchPagedResponse;
import com.google.ads.googleads.v17.services.MutateCustomerUserAccessResponse;
import com.google.ads.googleads.v17.utils.ResourceNames;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Iterator;
import java.util.Optional;

/**
* Cập nhật vai trò truy cập của người dùng dựa trên địa chỉ email. Lưu ý: Để chạy lệnh này, bạn phải có quyền quản trị viên trên tài khoản Google Ads được chỉ định với mã khách hàng tương ứng. Xem thêm về các cấp độ truy cập tại https://support.google.com/google-ads/answer/9978556.
*/

public class UpdateUserAccess {

private static class UpdateUserAccessParams extends CodeSampleParams {

@Parameter(names = ArgumentNames.CUSTOMER_ID, required = true)
private Long customerId;

@Parameter(names = ArgumentNames.EMAIL_ADDRESS, required = true)
private String emailAddress;

@Parameter(names = ArgumentNames.ACCESS_ROLE, required = true)
private AccessRole accessRole;
}

public static void main(String[] args) {
UpdateUserAccessParams params = new UpdateUserAccessParams();
if (!params.parseArguments(args)) {
params.customerId = Long.parseLong(“INSERT_CUSTOMER_ID_HERE”);
params.emailAddress = “INSERT_EMAIL_ADDRESS_HERE”;
params.accessRole = AccessRole.valueOf(“INSERT_ACCESS_ROLE_HERE”);
}

GoogleAdsClient googleAdsClient = null;
try {
googleAdsClient = GoogleAdsClient.newBuilder().fromPropertiesFile().build();
} catch (FileNotFoundException fnfe) {
System.err.printf(“Failed to load GoogleAdsClient configuration from file. Exception: %s%n”, fnfe);
System.exit(1);
} catch (IOException ioe) {
System.err.printf(“Failed to create GoogleAdsClient. Exception: %s%n”, ioe);
System.exit(1);
}

try {
new UpdateUserAccess().runExample(googleAdsClient, params.customerId, params.emailAddress, params.accessRole);
} catch (GoogleAdsException gae) {
System.err.printf(“Request ID %s failed due to GoogleAdsException. Underlying errors:%n”, gae.getRequestId());
int i = 0;
for (GoogleAdsError googleAdsError : gae.getGoogleAdsFailure().getErrorsList()) {
System.err.printf(” Error %d: %s%n”, i++, googleAdsError);
}
System.exit(1);
}
}

private void runExample(GoogleAdsClient googleAdsClient, long customerId, String emailAddress, AccessRole accessRole) {
Optional<CustomerUserAccess> accessInfo = getCustomerUserAccess(googleAdsClient, customerId, emailAddress);
if (accessInfo.isPresent()) {
modifyUserAccess(googleAdsClient, customerId, accessInfo.get().getUserId(), accessRole);
} else {
System.out.printf(“Email address ‘%s’ not found in customer ‘%s’.%n”, emailAddress, customerId);
}
}

private Optional<CustomerUserAccess> getCustomerUserAccess(GoogleAdsClient googleAdsClient, long customerId, String emailAddress) {
String query = String.format(
“SELECT customer_user_access.user_id, customer_user_access.email_address, customer_user_access.access_role, customer_user_access.access_creation_date_time FROM customer_user_access WHERE customer_user_access.email_address LIKE ‘%s'”, emailAddress);

try (GoogleAdsServiceClient googleAdsServiceClient = googleAdsClient.getLatestVersion().createGoogleAdsServiceClient()) {
SearchPagedResponse response = googleAdsServiceClient.search(String.valueOf(customerId), query);
Iterator<GoogleAdsRow> iterator = response.iterateAll().iterator();
if (iterator.hasNext()) {
CustomerUserAccess accessDetails = iterator.next().getCustomerUserAccess();
System.out.printf(“Customer user access with User ID = %d, Email Address = %s, Access Role = %s and Creation Time = %s was found in Customer ID: %d.%n”,
accessDetails.getUserId(), accessDetails.getEmailAddress(), accessDetails.getAccessRole(), accessDetails.getAccessCreationDateTime(), customerId);
return Optional.of(accessDetails);
}
return Optional.empty();
}
}

private void modifyUserAccess(GoogleAdsClient googleAdsClient, long customerId, long userId, AccessRole accessRole) {
CustomerUserAccess updatedAccess = CustomerUserAccess.newBuilder()
.setResourceName(ResourceNames.customerUserAccess(customerId, userId))
.setAccessRole(accessRole)
.build();

CustomerUserAccessOperation operation = CustomerUserAccessOperation.newBuilder()
.setUpdate(updatedAccess)
.setUpdateMask(FieldMasks.allSetFieldsOf(updatedAccess))
.build();

try (CustomerUserAccessServiceClient userAccessServiceClient = googleAdsClient.getLatestVersion().createCustomerUserAccessServiceClient()) {
MutateCustomerUserAccessResponse response = userAccessServiceClient.mutateCustomerUserAccess(String.valueOf(customerId), operation);
System.out.printf(“Successfully modified customer user access with resource name ‘%s’ to access level ‘%s’.%n”, response.getResult().getResourceName(), accessRole);
}
}
}

Việc quản lý quyền truy cập vào tài khoản Google Ads là một bước thiết yếu để bảo vệ tài khoản và đảm bảo rằng các hành động được thực hiện bởi những người có thẩm quyền. Bằng cách sử dụng Google Ads API, bạn có thể kiểm soát quyền truy cập của người dùng một cách dễ dàng và hiệu quả, từ việc truy vấn danh sách người dùng cho đến sửa đổi quyền truy cập của họ. Điều này giúp bạn duy trì tính bảo mật và tối ưu hóa quản lý tài khoản của mình. Hãy luôn cập nhật và kiểm tra quyền truy cập tài khoản của bạn để đảm bảo rằng chỉ những người có quyền mới có thể thực hiện các thao tác quan trọng trong Google Ads.

Facebook
X
LinkedIn
Tumblr
Threads
logo_v4seowebsite

V4SEO là đội ngũ SEO & Web xuất phát từ Nha Trang, triển khai dự án cho doanh nghiệp trên toàn quốc. Chúng tôi cung cấp Dịch vụ SEO Nha Trang theo chuẩn Google, kết hợp kỹ thuật, nội dung và entity để tăng trưởng bền vững. Song song, Dịch vụ thiết kế website Nha Trang tối ưu UX, tốc độ và Core Web Vitals nhằm tối đa chuyển đổi; báo cáo minh bạch, hỗ trợ dài hạn.

Nội dung được sự cố vấn của chuyên gia SEO - Võ Quang Vinh
author-founder-v4seowebsite

Võ Quang Vinh – Chuyên gia SEO với hơn 10 năm kinh nghiệm triển khai hàng trăm dự án SEO tổng thể, từ thương mại điện tử đến dịch vụ địa phương. Từng đảm nhiệm vai trò SEO và là Keymember tại Gobranding và dân dắt đội SEO BachhoaXanh.com, anh là người đứng sau nhiều chiến dịch tăng trưởng traffic vượt bậc. Hiện tại, Vinh là người sáng lập và điều hành V4SEO, cung cấp giải pháp SEO & thiết kế website chuẩn UX/UI giúp doanh nghiệp bứt phá thứ hạng Google và tối ưu chuyển đổi. 

Bài viết liên quan
ĐĂNG KÝ V4SEO NGAY HÔM NAY KHUYẾN MÃI 15% TẤT CẢ DỊCH VỤ ÁP DỤNG TỚI HẾT THÁNG 12/2025

Nhận tư vấn từ V4SEO Đăng ký ngay hôm nay Bứt phá trong mai sau