获取 LFP 商家状态
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
用于获取 LFP 商家状态的 Merchant API 代码示例。
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);
}
}
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-21。
[null,null,["最后更新时间 (UTC):2025-08-21。"],[],[],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"]]