Lấy trạng thái người bán LFP
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.
Mã mẫu Merchant API để lấy trạng thái người bán LFP.
Java
// 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.
package shopping.merchant.samples.lfp.v1;
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.lfp.v1.GetLfpMerchantStateRequest;
import com.google.shopping.merchant.lfp.v1.LfpMerchantState;
import com.google.shopping.merchant.lfp.v1.LfpMerchantStateName;
import com.google.shopping.merchant.lfp.v1.LfpMerchantStateServiceClient;
import com.google.shopping.merchant.lfp.v1.LfpMerchantStateServiceSettings;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;
/** This class demonstrates how to get the LFP state for a given Merchant Center account */
public class GetLfpMerchantStateSample {
public static void getLfpMerchantState(Config config, String targetMerchantId) throws Exception {
// Obtains OAuth token based on the user's configuration.
GoogleCredentials credential = new Authenticator().authenticate();
// Creates service settings using the credentials retrieved above.
LfpMerchantStateServiceSettings lfpMerchantStateServiceSettings =
LfpMerchantStateServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
// Gets the LFP account ID from the user's configuration.
String lfpAccountId = config.getAccountId().toString();
// Calls the API and catches and prints any network failures/errors.
try (LfpMerchantStateServiceClient lfpMerchantStateServiceClient =
LfpMerchantStateServiceClient.create(lfpMerchantStateServiceSettings)) {
GetLfpMerchantStateRequest request =
GetLfpMerchantStateRequest.newBuilder()
.setName(LfpMerchantStateName.of(lfpAccountId, targetMerchantId).toString())
.build();
System.out.println("Sending get LFP merchant state request:");
LfpMerchantState response = lfpMerchantStateServiceClient.getLfpMerchantState(request);
System.out.println("Retrieved LFP merchant state below:");
System.out.println(response);
} catch (Exception e) {
System.out.println(e);
}
}
public static void main(String[] args) throws Exception {
Config config = Config.load();
// The Merchant Center account ID.
String targetMerchantId = "{target_merchant}";
getLfpMerchantState(config, targetMerchantId);
}
}
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-08-21 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-08-21 UTC."],[],[],null,["# Get a LFP merchant state\n\nMerchant API code sample to get a LFP merchant state. \n\n### Java\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 package shopping.merchant.samples.lfp.v1;\n\n import com.google.api.gax.core.FixedCredentialsProvider;\n import com.google.auth.oauth2.GoogleCredentials;\n import com.google.shopping.merchant.lfp.v1.GetLfpMerchantStateRequest;\n import com.google.shopping.merchant.lfp.v1.LfpMerchantState;\n import com.google.shopping.merchant.lfp.v1.LfpMerchantStateName;\n import com.google.shopping.merchant.lfp.v1.LfpMerchantStateServiceClient;\n import com.google.shopping.merchant.lfp.v1.LfpMerchantStateServiceSettings;\n import shopping.merchant.samples.utils.Authenticator;\n import shopping.merchant.samples.utils.Config;\n\n /** This class demonstrates how to get the LFP state for a given Merchant Center account */\n public class GetLfpMerchantStateSample {\n\n public static void getLfpMerchantState(Config config, String targetMerchantId) 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 LfpMerchantStateServiceSettings lfpMerchantStateServiceSettings =\n LfpMerchantStateServiceSettings.newBuilder()\n .setCredentialsProvider(FixedCredentialsProvider.create(credential))\n .build();\n\n // Gets the LFP account ID from the user's configuration.\n String lfpAccountId = config.getAccountId().toString();\n // Calls the API and catches and prints any network failures/errors.\n try (LfpMerchantStateServiceClient lfpMerchantStateServiceClient =\n LfpMerchantStateServiceClient.create(lfpMerchantStateServiceSettings)) {\n\n GetLfpMerchantStateRequest request =\n GetLfpMerchantStateRequest.newBuilder()\n .setName(LfpMerchantStateName.of(lfpAccountId, targetMerchantId).toString())\n .build();\n\n System.out.println(\"Sending get LFP merchant state request:\");\n LfpMerchantState response = lfpMerchantStateServiceClient.getLfpMerchantState(request);\n\n System.out.println(\"Retrieved LFP merchant state 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 // The Merchant Center account ID.\n String targetMerchantId = \"{target_merchant}\";\n\n getLfpMerchantState(config, targetMerchantId);\n }\n } \n https://github.com/google/merchant-api-samples/blob/c6de994268c785ce22af0065932518a9ac5b3c03/java/src/main/java/shopping/merchant/samples/lfp/v1/GetLfpMerchantStateSample.java"]]