Để thảo luận và đưa ra ý kiến phản hồi về các sản phẩm của chúng tôi, hãy tham gia kênh Discord chính thức của Google Ads trong máy chủ Cộng đồng quảng cáo và đo lường của Google.
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Như đã thảo luận trong hướng dẫn về cấu trúc API, mỗi tài nguyên cấp cao nhất trong API Google Ads đều có một dịch vụ tương ứng dành riêng cho loại tài nguyên, hỗ trợ việc sửa đổi các thực thể của tài nguyên.
Hướng dẫn này sẽ sử dụng CampaignService để minh hoạ cách sửa đổi các đối tượng Campaign, nhưng các khái niệm tương tự cũng áp dụng cho tất cả các dịch vụ khác dành riêng cho loại tài nguyên.
Thay đổi đối tượng
Mỗi dịch vụ dành riêng cho loại tài nguyên sẽ có một phương thức mutate chấp nhận yêu cầu mutate. Yêu cầu này bao gồm:
customerId
Một tập hợp các thao tác
Một chế độ cài đặt content-type của phản hồi xác định xem tài nguyên có thể thay đổi hay chỉ tên tài nguyên sẽ được trả về sau khi thay đổi.
Ví dụ: phương thức MutateCampaigns của CampaignService chấp nhận một MutateCampaignsRequest bao gồm:
customerId
Một tập hợp các đối tượng CampaignOperation
Trường response_content_type cho biết loại câu trả lời ưu tiên.
Hoạt động tính toán
Một đối tượng thao tác như CampaignOperation cho phép bạn chỉ định hành động mà bạn muốn thực hiện trên một tài nguyên duy nhất bằng cách đặt trường operation của tài nguyên đó. Trường này là một trường oneof bao gồm các thuộc tính sau có loại là loại tài nguyên:
create
Tạo một phiên bản mới của tài nguyên.
update
Cập nhật tài nguyên để khớp với các thuộc tính của tài nguyên update.
Khi đặt trường này, bạn cũng phải đặt update_mask của thao tác. Trường này cho biết API Google Ads cần sửa đổi những thuộc tính nào trong quá trình thực hiện thao tác cập nhật. Mỗi thư viện ứng dụng đều có một phương thức tiện ích hoặc phương thức trợ giúp sẽ tạo update_mask cho bạn, như minh hoạ trong thư viện ứng dụng của chúng tôi.
remove
Xoá tài nguyên.
Vì trường operation là trường oneof, bạn không thể dùng một thao tác duy nhất để sửa đổi nhiều đối tượng. Ví dụ: nếu bạn muốn tạo một chiến dịch và xoá một chiến dịch khác, hãy thêm hai phiên bản của CampaignOperation vào yêu cầu của bạn: một phiên bản có create được đặt và một phiên bản khác có remove được đặt.
Thao tác theo đợt
Mặc dù một thao tác chỉ có thể tạo, cập nhật hoặc xoá một tài nguyên duy nhất, nhưng một yêu cầu biến đổi duy nhất có thể chứa nhiều thao tác. Bạn nên kết hợp các thao tác thành một yêu cầu biến đổi duy nhất thay vì gửi nhiều yêu cầu biến đổi, mỗi yêu cầu chứa một thao tác duy nhất.
Ví dụ: nếu muốn tạo 10 chiến dịch, bạn nên gửi một MutateCampaignsRequest có 10 đối tượng CampaignOperation.
Thay đổi phản hồi
Nội dung được trả về trong phản hồi phụ thuộc vào nội dung đã được gửi trong response_content_type của yêu cầu biến đổi. Ví dụ: nếu bạn chỉ định MUTABLE_RESOURCE, thì phản hồi sẽ chỉ chứa các trường có thể thay đổi trong chiến dịch. Sau đó, bạn có thể thực hiện các thao tác thay đổi tiếp theo trên đối tượng tài nguyên đó mà không cần phải tạo lại.
Lỗi thay đổi
Các thao tác trong một yêu cầu biến đổi nhất định sẽ chỉ được áp dụng cho tài khoản Google Ads của bạn nếu mọi thao tác trong yêu cầu đều thành công. Hãy xem hướng dẫn về các lỗi thường gặp để biết danh sách các lỗi thường gặp và cách giải quyết.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-09-05 UTC."],[[["\u003cp\u003eUse the Google Ads API to modify and inspect objects, such as campaigns, through their respective services.\u003c/p\u003e\n"],["\u003cp\u003eEach resource-type-specific service has a mutate method to create, update, or remove instances of that resource type.\u003c/p\u003e\n"],["\u003cp\u003eOperations within a single mutate request are atomic; all operations must succeed for any changes to be applied.\u003c/p\u003e\n"],["\u003cp\u003eBatch multiple operations into a single mutate request for efficiency, instead of sending individual requests.\u003c/p\u003e\n"],["\u003cp\u003eSpecify a response content type to control the data returned in the response, potentially streamlining further interactions.\u003c/p\u003e\n"]]],[],null,["# Change Objects\n\n| **Objective:** Understand how to modify objects using the Google Ads API.\n\nAs discussed in the [API structure guide](/google-ads/api/docs/concepts/api-structure), each\ntop-level resource in the Google Ads API has a corresponding resource-type-specific\nservice that supports modifying instances of the resource.\n\nThis guide will use [`CampaignService`](/google-ads/api/reference/rpc/v21/CampaignService) to\ndemonstrate modifying [`Campaign`](/google-ads/api/reference/rpc/v21/Campaign)\nobjects, but the same concepts apply to all other resource-type-specific\nservices.\n| **Key Term:** A top-level resource is a [resource](/google-ads/api/reference/rpc/v21/overview#resources) whose name does not include a period (`.`). For example, `Campaign` is a top-level resource, but `Campaign.NetworkSettings` is not.\n\nChange objects\n--------------\n\nEach resource-type-specific service will have a *mutate* method that accepts\na mutate request. This request consists of:\n\n- A `customerId`\n- A collection of operations\n- A response content-type setting that determines whether the mutable resource or just the resource name should be returned post mutation.\n\nFor example, the `MutateCampaigns` method of `CampaignService` accepts a\n[`MutateCampaignsRequest`](/google-ads/api/reference/rpc/v21/MutateCampaignsRequest) that consists\nof:\n\n- A `customerId`\n- A collection of `CampaignOperation` objects\n- The `response_content_type` field indicating the preferred response type.\n\n### Operations\n\nAn operation object such as a `CampaignOperation` lets you specify the\naction that you want to perform on a single resource by setting its `operation`\nfield. This field is a\n[oneof field](//protobuf.dev/programming-guides/proto3/#oneof)\nconsisting of the following attributes whose type is the resource type:\n\n`create`\n: Creates a new instance of the resource.\n\n`update`\n: Updates the resource to match the attributes of the `update` resource.\n When this field is set, you must also set the `update_mask` of the\n operation, which tells the Google Ads API which attributes to modify during\n the update operation. Each [client library](/google-ads/api/docs/client-libs) has a\n utility or helper method that will generate the `update_mask` for you, as\n demonstrated in our [client libraries](/google-ads/api/docs/client-libs).\n\n`remove`\n: Removes the resource.\n\nSince the `operation` field is a `oneof` field, you cannot use a single\noperation to modify multiple objects. For example, if you want to create one\ncampaign and remove another campaign, add two instances of `CampaignOperation`\nto your request: one with `create` set, and another with `remove` set.\n\n### Batch operations\n\nAlthough a single operation can only either create, update, or remove a single\nresource, a single mutate request can contain multiple operations. You should\ncombine your operations into a single mutate request instead of sending multiple\nmutate requests that each contain a single operation.\n\nFor example, if you want to create ten campaigns, you should send a\n*single* `MutateCampaignsRequest` that has ten `CampaignOperation` objects.\n\n### Mutate responses\n\nWhat is returned in the response depends on what was sent in the\n[`response_content_type`](/google-ads/api/reference/rpc/v21/ResponseContentTypeEnum.ResponseContentType)\nof the mutate request. For example, if `MUTABLE_RESOURCE` was specified, then\nthe [response](/google-ads/api/reference/rpc/v21/MutateCampaignsResponse) would contain just the\nmutable fields in the campaign. You can then make follow-up mutates on that\nresource object without having to reconstruct it.\n\n### Mutate errors\n\nThe operations in a given mutate request will only be applied to your Google Ads\naccount if *every* operation in the request succeeds. Check out the\n[common errors guide](/google-ads/api/docs/common-errors) for a list of common\nerrors and how to address them."]]