Labels-MC-Konto aktualisieren
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Verwenden Sie dieses Beispiel, um Kontolabels für ein MC-Konto zu aktualisieren.
cURL
curl --location --request POST 'https://css.googleapis.com/v1/accounts/987654321:updateLabels?labelIds=1000012345&parent=accounts/1234567' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <API_TOKEN>'
Java
// Copyright 2023 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 shopping.css.samples.v1.accounts;
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.css.v1.Account;
import com.google.shopping.css.v1.AccountsServiceClient;
import com.google.shopping.css.v1.AccountsServiceSettings;
import com.google.shopping.css.v1.UpdateAccountLabelsRequest;
import java.util.Arrays;
import java.util.List;
import shopping.css.samples.utils.Authenticator;
import shopping.css.samples.utils.Config;
/** This class demonstrates how to update AccountLabels for a given MC Account */
public class UpdateLabelsMcAccount {
private static String getName(String domainId) {
return String.format("accounts/%s", domainId);
}
public static void updateLabelsMcAccount(Config config, List<Long> labelIds) throws Exception {
GoogleCredentials credential = new Authenticator().authenticate();
AccountsServiceSettings accountsServiceSettings =
AccountsServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
String name = getName(config.getMerchantId().toString());
String parent = getName(config.getDomainId().toString());
try (AccountsServiceClient accountsServiceClient =
AccountsServiceClient.create(accountsServiceSettings)) {
UpdateAccountLabelsRequest request =
UpdateAccountLabelsRequest.newBuilder()
.setName(name)
.addAllLabelIds(labelIds)
.setParent(parent)
.build();
System.out.println("Sending UpdateLabels request");
Account response = accountsServiceClient.updateLabels(request);
System.out.println("Updated Account below");
System.out.println(response);
} catch (Exception e) {
System.out.println(e);
}
}
public static void main(String[] args) throws Exception {
final Config config = Config.load();
// The AccountLabel IDs to be assigned to the MC account. Leave the list empty to delete all
// assigned labels
List<Long> labelIds = Arrays.asList(10000123456L, 10000123457L);
updateLabelsMcAccount(config, labelIds);
}
}
Sofern nicht anders angegeben, sind die Inhalte dieser Seite unter der Creative Commons Attribution 4.0 License und Codebeispiele unter der Apache 2.0 License lizenziert. Weitere Informationen finden Sie in den Websiterichtlinien von Google Developers. Java ist eine eingetragene Marke von Oracle und/oder seinen Partnern.
Zuletzt aktualisiert: 2025-07-25 (UTC).
[null,null,["Zuletzt aktualisiert: 2025-07-25 (UTC)."],[[["\u003cp\u003eThis documentation provides a guide and code samples for updating account labels for a multi-client (MC) account using the Content API for Shopping.\u003c/p\u003e\n"],["\u003cp\u003eIt includes examples in both cURL and Java, demonstrating how to send a request to update the labels associated with an MC account.\u003c/p\u003e\n"],["\u003cp\u003eThe Java example utilizes the Google CSS API client library for Java and requires proper authentication credentials.\u003c/p\u003e\n"],["\u003cp\u003eTo remove all labels from an account, an empty list of label IDs should be provided in the update request.\u003c/p\u003e\n"]]],[],null,["# Update Labels MC Account\n\nUse this sample to update Account Labels for an MC Account. \n\n### cURL\n\n curl --location --request POST 'https://css.googleapis.com/v1/accounts/987654321:updateLabels?labelIds=1000012345&parent=accounts/1234567' \\\n --header 'Content-Type: application/json' \\\n --header 'Authorization: Bearer \u003cAPI_TOKEN\u003e'\n\n### Java\n\n // Copyright 2023 Google LLC\n //\n // Licensed under the Apache License, Version 2.0 (the \"License\");\n // you may not use this file except in compliance with the License.\n // You may obtain a copy of the License at\n //\n // https://www.apache.org/licenses/LICENSE-2.0\n //\n // Unless required by applicable law or agreed to in writing, software\n // distributed under the License is distributed on an \"AS IS\" BASIS,\n // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n // See the License for the specific language governing permissions and\n // limitations under the License.\n\n package shopping.css.samples.v1.accounts;\n\n import com.google.api.gax.core.FixedCredentialsProvider;\n import com.google.auth.oauth2.GoogleCredentials;\n import com.google.shopping.css.v1.Account;\n import com.google.shopping.css.v1.AccountsServiceClient;\n import com.google.shopping.css.v1.AccountsServiceSettings;\n import com.google.shopping.css.v1.UpdateAccountLabelsRequest;\n import java.util.Arrays;\n import java.util.List;\n import shopping.css.samples.utils.Authenticator;\n import shopping.css.samples.utils.Config;\n\n /** This class demonstrates how to update AccountLabels for a given MC Account */\n public class UpdateLabelsMcAccount {\n\n private static String getName(String domainId) {\n return String.format(\"accounts/%s\", domainId);\n }\n\n public static void updateLabelsMcAccount(Config config, List\u003cLong\u003e labelIds) throws Exception {\n GoogleCredentials credential = new Authenticator().authenticate();\n\n AccountsServiceSettings accountsServiceSettings =\n AccountsServiceSettings.newBuilder()\n .setCredentialsProvider(FixedCredentialsProvider.create(credential))\n .build();\n\n String name = getName(config.getMerchantId().toString());\n String parent = getName(config.getDomainId().toString());\n\n try (AccountsServiceClient accountsServiceClient =\n AccountsServiceClient.create(accountsServiceSettings)) {\n\n UpdateAccountLabelsRequest request =\n UpdateAccountLabelsRequest.newBuilder()\n .setName(name)\n .addAllLabelIds(labelIds)\n .setParent(parent)\n .build();\n\n System.out.println(\"Sending UpdateLabels request\");\n Account response = accountsServiceClient.updateLabels(request);\n System.out.println(\"Updated Account below\");\n System.out.println(response);\n } catch (Exception e) {\n System.out.println(e);\n }\n }\n\n public static void main(String[] args) throws Exception {\n final Config config = Config.load();\n // The AccountLabel IDs to be assigned to the MC account. Leave the list empty to delete all\n // assigned labels\n List\u003cLong\u003e labelIds = Arrays.asList(10000123456L, 10000123457L);\n\n updateLabelsMcAccount(config, labelIds);\n }\n } \n https://github.com/googleads/comparison-shopping-service-api-samples/blob/2f511c3ca413bdbd497f89ae7468b3191dafaa6d/java/src/main/java/shopping/css/samples/v1/accounts/UpdateLabelsMcAccount.java"]]