دریافت حساب MC، دریافت حساب MC
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
از این نمونه برای دریافت حساب MC استفاده کنید.
CURL
curl --location 'https://css.googleapis.com/v1/accounts/987654321?parent=accounts/1234567' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <API_TOKEN>'
جاوا
// 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.GetAccountRequest;
import shopping.css.samples.utils.Authenticator;
import shopping.css.samples.utils.Config;
/** This class demonstrates how to get an MC Account */
public class GetMcAccount {
private static String getName(String accountId) {
return String.format("accounts/%s", accountId);
}
public static void getMcAccount(Config config) 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)) {
GetAccountRequest request =
GetAccountRequest.newBuilder().setName(name).setParent(parent).build();
System.out.println("Sending GetAccount request");
Account response = accountsServiceClient.getAccount(request);
System.out.println("Retrieved MC 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();
getMcAccount(config);
}
}
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-07-24 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-07-24 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eThis page provides instructions and code samples for retrieving an MC (Multi-Client) Account using the Comparison Shopping Service (CSS) API.\u003c/p\u003e\n"],["\u003cp\u003eCode examples are given in both cURL and Java, demonstrating how to make the API request.\u003c/p\u003e\n"],["\u003cp\u003eThe Java example utilizes the Google Cloud Client Library for Java and requires authentication with Google Cloud.\u003c/p\u003e\n"],["\u003cp\u003eThe provided code snippets can be used to fetch account details based on Merchant Center and Domain IDs.\u003c/p\u003e\n"]]],[],null,["# Get MC Account\n\nUse this sample to get an MC Account. \n\n### cURL\n\n curl --location 'https://css.googleapis.com/v1/accounts/987654321?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.GetAccountRequest;\n import shopping.css.samples.utils.Authenticator;\n import shopping.css.samples.utils.Config;\n\n /** This class demonstrates how to get an MC Account */\n public class GetMcAccount {\n\n private static String getName(String accountId) {\n return String.format(\"accounts/%s\", accountId);\n }\n\n public static void getMcAccount(Config config) 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 GetAccountRequest request =\n GetAccountRequest.newBuilder().setName(name).setParent(parent).build();\n\n System.out.println(\"Sending GetAccount request\");\n Account response = accountsServiceClient.getAccount(request);\n System.out.println(\"Retrieved MC 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\n getMcAccount(config);\n }\n } \n https://github.com/googleads/comparison-shopping-service-api-samples/blob/2f511c3ca413bdbd497f89ae7468b3191dafaa6d/java/src/main/java/shopping/css/samples/v1/accounts/GetMcAccount.java"]]