إلغاء المطالبة بملكية صفحة رئيسية
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
نموذج لرمز Merchant API لإلغاء المطالبة بملكية صفحة رئيسية
Java
// Copyright 2024 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.merchant.samples.accounts.homepages.v1;
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.accounts.v1.Homepage;
import com.google.shopping.merchant.accounts.v1.HomepageName;
import com.google.shopping.merchant.accounts.v1.HomepageServiceClient;
import com.google.shopping.merchant.accounts.v1.HomepageServiceSettings;
import com.google.shopping.merchant.accounts.v1.UnclaimHomepageRequest;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;
/** This class demonstrates how to unclaim the homepage for a given Merchant Center account. */
public class UnclaimHomepageSample {
// Executing this method requires admin access.
public static void unclaimHomepage(Config config) throws Exception {
// Obtains OAuth token based on the user's configuration.
GoogleCredentials credential = new Authenticator().authenticate();
// Creates service settings using the credentials retrieved above.
HomepageServiceSettings homepageServiceSettings =
HomepageServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
// Creates Homepage name to identify Homepage.
// The name has the format: accounts/{account}/homepage
String name =
HomepageName.newBuilder().setAccount(config.getAccountId().toString()).build().toString();
// Calls the API and catches and prints any network failures/errors.
try (HomepageServiceClient homepageServiceClient =
HomepageServiceClient.create(homepageServiceSettings)) {
UnclaimHomepageRequest request = UnclaimHomepageRequest.newBuilder().setName(name).build();
System.out.println("Sending Unclaim Homepage request:");
Homepage response = homepageServiceClient.unclaimHomepage(request);
System.out.println("Retrieved Homepage below");
System.out.println(response);
} catch (Exception e) {
System.out.println(e);
}
}
public static void main(String[] args) throws Exception {
Config config = Config.load();
unclaimHomepage(config);
}
}
PHP
<?php
/**
* Copyright 2025 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.
*/
require_once __DIR__ . '/../../../../vendor/autoload.php';
require_once __DIR__ . '/../../../Authentication/Authentication.php';
require_once __DIR__ . '/../../../Authentication/Config.php';
use Google\ApiCore\ApiException;
use Google\Shopping\Merchant\Accounts\V1\Client\HomepageServiceClient;
use Google\Shopping\Merchant\Accounts\V1\UnclaimHomepageRequest;
/**
* This class demonstrates how to unclaim the homepage for a given Merchant Center account.
*/
class UnclaimHomepage
{
/**
* Unclaims the homepage for a given Merchant Center account.
*
* @param array $config The configuration data for authentication and account ID.
* @return void
* @throws ApiException if the API call fails.
*/
public static function unclaimHomepageSample(array $config): void
{
// Gets the OAuth credentials to make the request.
$credentials = Authentication::useServiceAccountOrTokenFile();
// Creates options config containing credentials for the client to use.
$options = ['credentials' => $credentials];
// Creates a client.
$homepageServiceClient = new HomepageServiceClient($options);
// Creates Homepage name to identify Homepage.
// The name has the format: accounts/{account}/homepage
$name = "accounts/" . $config['accountId'] . "/homepage";
// Calls the API and catches and prints any network failures/errors.
try {
$request = new UnclaimHomepageRequest(['name' => $name]);
print "Sending Unclaim Homepage request:\n";
$response = $homepageServiceClient->unclaimHomepage($request);
print "Retrieved Homepage below\n";
print_r($response);
} catch (ApiException $e) {
print $e->getMessage();
}
}
/**
* Helper to execute the sample.
*
* @return void
*/
public function callSample(): void
{
$config = Config::generateConfig();
// Makes the call to unclaim the homepage.
self::unclaimHomepageSample($config);
}
}
// Run the script
$sample = new UnclaimHomepage();
$sample->callSample();
Python
# -*- coding: utf-8 -*-
# Copyright 2025 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
#
# http://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.
"""A module to unclaim a Homepage."""
from examples.authentication import configuration
from examples.authentication import generate_user_credentials
from google.shopping.merchant_accounts_v1 import HomepageServiceClient
from google.shopping.merchant_accounts_v1 import UnclaimHomepageRequest
_ACCOUNT = configuration.Configuration().read_merchant_info()
def unclaim_homepage():
"""Unclaims the homepage for a given Merchant Center account."""
# Gets OAuth Credentials.
credentials = generate_user_credentials.main()
# Creates a client.
client = HomepageServiceClient(credentials=credentials)
# Creates Homepage name to identify Homepage.
# The name has the format: accounts/{account}/homepage
name = "accounts/" + _ACCOUNT + "/homepage"
# Creates the request.
request = UnclaimHomepageRequest(name=name)
# Makes the request and catches and prints any error messages.
try:
response = client.unclaim_homepage(request=request)
print(f"Unclaimed Homepage: {response}")
except RuntimeError as e:
print(f"Failed to unclaim homepage: {e}")
if __name__ == "__main__":
unclaim_homepage()
إنّ محتوى هذه الصفحة مرخّص بموجب ترخيص Creative Commons Attribution 4.0 ما لم يُنصّ على خلاف ذلك، ونماذج الرموز مرخّصة بموجب ترخيص Apache 2.0. للاطّلاع على التفاصيل، يُرجى مراجعة سياسات موقع Google Developers. إنّ Java هي علامة تجارية مسجَّلة لشركة Oracle و/أو شركائها التابعين.
تاريخ التعديل الأخير: 2025-08-21 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-08-21 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\u003cp\u003eThis webpage provides code samples in Java and Python for unclaiming a homepage associated with a Merchant Center account using the Merchant API.\u003c/p\u003e\n"],["\u003cp\u003eThe Java code demonstrates how to create a \u003ccode\u003eHomepageServiceClient\u003c/code\u003e, authenticate with OAuth, construct an \u003ccode\u003eUnclaimHomepageRequest\u003c/code\u003e, and execute the unclaim operation, retrieving the response.\u003c/p\u003e\n"],["\u003cp\u003eThe Python example outlines the process of obtaining OAuth credentials, establishing a \u003ccode\u003eHomepageServiceClient\u003c/code\u003e, creating an \u003ccode\u003eUnclaimHomepageRequest\u003c/code\u003e, and making the request to unclaim the homepage.\u003c/p\u003e\n"],["\u003cp\u003eBoth code samples show how to use the respective client libraries, \u003ccode\u003eHomepageServiceClient\u003c/code\u003e in Java and Python, to successfully unclaim the homepage, and handling the potential errors.\u003c/p\u003e\n"]]],["The provided code demonstrates how to unclaim a homepage for a Merchant Center account using the Merchant API in Java, PHP, and Python. The process involves obtaining OAuth credentials, creating a `HomepageServiceClient`, and constructing a `UnclaimHomepageRequest` with the account's homepage name. This request is then sent to the API via `unclaimHomepage()`, and the response (or any encountered errors) is outputted. This operation requires admin access.\n"],null,["# Unclaim an homepage\n\nMerchant API code sample to unclaim an homepage. \n\n### Java\n\n // Copyright 2024 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.merchant.samples.accounts.homepages.v1;\n import com.google.api.gax.core.FixedCredentialsProvider;\n import com.google.auth.oauth2.GoogleCredentials;\n import com.google.shopping.merchant.accounts.v1.Homepage;\n import com.google.shopping.merchant.accounts.v1.HomepageName;\n import com.google.shopping.merchant.accounts.v1.HomepageServiceClient;\n import com.google.shopping.merchant.accounts.v1.HomepageServiceSettings;\n import com.google.shopping.merchant.accounts.v1.UnclaimHomepageRequest;\n import shopping.merchant.samples.utils.Authenticator;\n import shopping.merchant.samples.utils.Config;\n\n /** This class demonstrates how to unclaim the homepage for a given Merchant Center account. */\n public class UnclaimHomepageSample {\n\n // Executing this method requires admin access.\n public static void unclaimHomepage(Config config) throws Exception {\n\n // Obtains OAuth token based on the user's configuration.\n GoogleCredentials credential = new Authenticator().authenticate();\n\n // Creates service settings using the credentials retrieved above.\n HomepageServiceSettings homepageServiceSettings =\n HomepageServiceSettings.newBuilder()\n .setCredentialsProvider(FixedCredentialsProvider.create(credential))\n .build();\n\n // Creates Homepage name to identify Homepage.\n // The name has the format: accounts/{account}/homepage\n String name =\n HomepageName.newBuilder().setAccount(config.getAccountId().toString()).build().toString();\n\n // Calls the API and catches and prints any network failures/errors.\n try (HomepageServiceClient homepageServiceClient =\n HomepageServiceClient.create(homepageServiceSettings)) {\n\n UnclaimHomepageRequest request = UnclaimHomepageRequest.newBuilder().setName(name).build();\n\n System.out.println(\"Sending Unclaim Homepage request:\");\n\n Homepage response = homepageServiceClient.unclaimHomepage(request);\n\n System.out.println(\"Retrieved Homepage 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 Config config = Config.load();\n\n unclaimHomepage(config);\n }\n } \n https://github.com/google/merchant-api-samples/blob/c6de994268c785ce22af0065932518a9ac5b3c03/java/src/main/java/shopping/merchant/samples/accounts/homepages/v1/UnclaimHomepageSample.java\n\n### PHP\n\n \u003c?php\n /**\n * Copyright 2025 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 require_once __DIR__ . '/../../../../vendor/autoload.php';\n require_once __DIR__ . '/../../../Authentication/Authentication.php';\n require_once __DIR__ . '/../../../Authentication/Config.php';\n use Google\\ApiCore\\ApiException;\n use Google\\Shopping\\Merchant\\Accounts\\V1\\Client\\HomepageServiceClient;\n use Google\\Shopping\\Merchant\\Accounts\\V1\\UnclaimHomepageRequest;\n\n /**\n * This class demonstrates how to unclaim the homepage for a given Merchant Center account.\n */\n class UnclaimHomepage\n {\n /**\n * Unclaims the homepage for a given Merchant Center account.\n *\n * @param array $config The configuration data for authentication and account ID.\n * @return void\n * @throws ApiException if the API call fails.\n */\n public static function unclaimHomepageSample(array $config): void\n {\n // Gets the OAuth credentials to make the request.\n $credentials = Authentication::useServiceAccountOrTokenFile();\n\n // Creates options config containing credentials for the client to use.\n $options = ['credentials' =\u003e $credentials];\n\n // Creates a client.\n $homepageServiceClient = new HomepageServiceClient($options);\n\n // Creates Homepage name to identify Homepage.\n // The name has the format: accounts/{account}/homepage\n $name = \"accounts/\" . $config['accountId'] . \"/homepage\";\n\n // Calls the API and catches and prints any network failures/errors.\n try {\n $request = new UnclaimHomepageRequest(['name' =\u003e $name]);\n\n print \"Sending Unclaim Homepage request:\\n\";\n\n $response = $homepageServiceClient-\u003eunclaimHomepage($request);\n\n print \"Retrieved Homepage below\\n\";\n print_r($response);\n } catch (ApiException $e) {\n print $e-\u003egetMessage();\n }\n }\n\n /**\n * Helper to execute the sample.\n *\n * @return void\n */\n public function callSample(): void\n {\n $config = Config::generateConfig();\n\n // Makes the call to unclaim the homepage.\n self::unclaimHomepageSample($config);\n }\n }\n\n\n // Run the script\n $sample = new UnclaimHomepage();\n $sample-\u003ecallSample(); \n https://github.com/google/merchant-api-samples/blob/c6de994268c785ce22af0065932518a9ac5b3c03/php/examples/accounts/homepages/v1/UnclaimHomepageSample.php\n\n### Python\n\n # -*- coding: utf-8 -*-\n # Copyright 2025 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 # http://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 \"\"\"A module to unclaim a Homepage.\"\"\"\n\n from examples.authentication import configuration\n from examples.authentication import generate_user_credentials\n from google.shopping.merchant_accounts_v1 import HomepageServiceClient\n from google.shopping.merchant_accounts_v1 import UnclaimHomepageRequest\n\n _ACCOUNT = configuration.Configuration().read_merchant_info()\n\n\n def unclaim_homepage():\n \"\"\"Unclaims the homepage for a given Merchant Center account.\"\"\"\n\n # Gets OAuth Credentials.\n credentials = generate_user_credentials.main()\n\n # Creates a client.\n client = HomepageServiceClient(credentials=credentials)\n\n # Creates Homepage name to identify Homepage.\n # The name has the format: accounts/{account}/homepage\n name = \"accounts/\" + _ACCOUNT + \"/homepage\"\n\n # Creates the request.\n request = UnclaimHomepageRequest(name=name)\n\n # Makes the request and catches and prints any error messages.\n try:\n response = client.unclaim_homepage(request=request)\n print(f\"Unclaimed Homepage: {response}\")\n except RuntimeError as e:\n print(f\"Failed to unclaim homepage: {e}\")\n\n\n if __name__ == \"__main__\":\n unclaim_homepage()\n\n https://github.com/google/merchant-api-samples/blob/c6de994268c785ce22af0065932518a9ac5b3c03/python/examples/accounts/homepages/v1/unclaim_homepage_sample.py"]]