Elimina etichetta account
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Utilizza questo esempio per eliminare un'etichetta account.
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.accountlabels;
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.css.v1.AccountLabelsServiceClient;
import com.google.shopping.css.v1.AccountLabelsServiceSettings;
import com.google.shopping.css.v1.DeleteAccountLabelRequest;
import shopping.css.samples.utils.Authenticator;
import shopping.css.samples.utils.Config;
/** This class demonstrates how to delete an AccountLabel for a given parent account */
public class DeleteAccountLabel {
private static String getName(String accountId, String labelId) {
return String.format("accounts/%s/labels/%s", accountId, labelId);
}
public static void deleteAccountLabel(Config config, String labelId) throws Exception {
GoogleCredentials credential = new Authenticator().authenticate();
AccountLabelsServiceSettings accountLabelsServiceSettings =
AccountLabelsServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
String name = getName(config.getDomainId().toString(), labelId);
try (AccountLabelsServiceClient accountLabelsServiceClient =
AccountLabelsServiceClient.create(accountLabelsServiceSettings)) {
DeleteAccountLabelRequest request =
DeleteAccountLabelRequest.newBuilder().setName(name).build();
System.out.println("Sending DeleteAccountLabel request");
accountLabelsServiceClient.deleteAccountLabel(request); // no response returned on success
System.out.println("Delete successful");
} catch (Exception e) {
System.out.println(e);
}
}
public static void main(String[] args) throws Exception {
final Config config = Config.load();
// The ID of the AccountLabel to be deleted
final String labelId = "10000123456";
deleteAccountLabel(config, labelId);
}
}
Salvo quando diversamente specificato, i contenuti di questa pagina sono concessi in base alla licenza Creative Commons Attribution 4.0, mentre gli esempi di codice sono concessi in base alla licenza Apache 2.0. Per ulteriori dettagli, consulta le norme del sito di Google Developers. Java è un marchio registrato di Oracle e/o delle sue consociate.
Ultimo aggiornamento 2025-07-25 UTC.
[null,null,["Ultimo aggiornamento 2025-07-25 UTC."],[[["\u003cp\u003eThis code sample demonstrates how to delete an existing Account Label using the Content API for Shopping.\u003c/p\u003e\n"],["\u003cp\u003eIt uses the \u003ccode\u003eDeleteAccountLabel\u003c/code\u003e method of the \u003ccode\u003eAccountLabelsServiceClient\u003c/code\u003e to send the deletion request.\u003c/p\u003e\n"],["\u003cp\u003eTo identify the Account Label to delete, you need to provide the \u003ccode\u003eaccountId\u003c/code\u003e and \u003ccode\u003elabelId\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eUpon successful deletion, there is no response returned; however, a success message will be printed to the console.\u003c/p\u003e\n"],["\u003cp\u003eRefer to the provided GitHub link for the complete code and further context.\u003c/p\u003e\n"]]],[],null,["# Delete Account Label\n\nUse this sample to delete an Account Label. \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.accountlabels;\n\n import com.google.api.gax.core.FixedCredentialsProvider;\n import com.google.auth.oauth2.GoogleCredentials;\n import com.google.shopping.css.v1.AccountLabelsServiceClient;\n import com.google.shopping.css.v1.AccountLabelsServiceSettings;\n import com.google.shopping.css.v1.DeleteAccountLabelRequest;\n import shopping.css.samples.utils.Authenticator;\n import shopping.css.samples.utils.Config;\n\n /** This class demonstrates how to delete an AccountLabel for a given parent account */\n public class DeleteAccountLabel {\n\n private static String getName(String accountId, String labelId) {\n return String.format(\"accounts/%s/labels/%s\", accountId, labelId);\n }\n\n public static void deleteAccountLabel(Config config, String labelId) throws Exception {\n GoogleCredentials credential = new Authenticator().authenticate();\n\n AccountLabelsServiceSettings accountLabelsServiceSettings =\n AccountLabelsServiceSettings.newBuilder()\n .setCredentialsProvider(FixedCredentialsProvider.create(credential))\n .build();\n\n String name = getName(config.getDomainId().toString(), labelId);\n\n try (AccountLabelsServiceClient accountLabelsServiceClient =\n AccountLabelsServiceClient.create(accountLabelsServiceSettings)) {\n\n DeleteAccountLabelRequest request =\n DeleteAccountLabelRequest.newBuilder().setName(name).build();\n\n System.out.println(\"Sending DeleteAccountLabel request\");\n accountLabelsServiceClient.deleteAccountLabel(request); // no response returned on success\n System.out.println(\"Delete successful\");\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 ID of the AccountLabel to be deleted\n final String labelId = \"10000123456\";\n\n deleteAccountLabel(config, labelId);\n }\n } \n https://github.com/googleads/comparison-shopping-service-api-samples/blob/2f511c3ca413bdbd497f89ae7468b3191dafaa6d/java/src/main/java/shopping/css/samples/v1/accountlabels/DeleteAccountLabel.java"]]