โปรแกรมพาร์ทเนอร์ทางธุรกิจสำหรับฟีดในร้านถือเป็นโอกาสที่ผู้ค้าปลีกจะได้ร่วมลงโฆษณาสินค้าคงคลังในร้านและข้อมูลในร้านที่แสดงฟรีโดยไม่ต้องสร้างฟีดหลักและฟีดสินค้าคงคลังของผลิตภัณฑ์ในร้านของตนเอง ผู้ให้บริการข้อมูลที่เชื่อถือได้จะให้ข้อมูลการขายหรือสินค้าคงคลังแก่ Google ในนามของผู้ค้าปลีกได้
ข้อกำหนดเบื้องต้น
หากต้องการใช้เมธอด API ในส่วนนี้ ให้สร้างโปรแกรมโฆษณาสินค้าคงคลังในร้าน (LIA) หรือข้อมูลในร้านที่แสดงฟรี (FLL) ก่อน โปรดดูรายละเอียดเพิ่มเติมที่หัวข้อจัดการการตั้งค่าช่องทางที่หลากหลาย
ค้นหาผู้ให้บริการ LFP ที่พร้อมให้บริการ
หากต้องการดึงข้อมูลผู้ให้บริการ LFP ทั้งหมดที่มีในประเทศ ให้ใช้
lfpProviders.findLfpProviders
POST
https://merchantapi.googleapis.com/accounts/v1beta/accounts/{ACCOUNT_ID}/omnichannelSettings/{REGION_CODE}/lfpProviders:find
แทนที่ค่าต่อไปนี้
{ACCOUNT_ID}
: ตัวระบุที่ไม่ซ้ำกันของบัญชี Merchant Center{REGION_CODE}
: รหัสภูมิภาคจากรายการที่โปรเจ็กต์ที่เก็บข้อมูลภาษาทั่วไป (CLDR) กำหนด
ตัวอย่างการตอบกลับที่สำเร็จ
200 OK
{
"lsfProviders": [
{
"name": "accounts/{ACCOUNT}/omnichannelSettings/{REGION_CODE}/lsfProviders/12345",
"regionCode": {REGION_CODE},
"displayName": "LFP Provider 1"
}, {
"name": "accounts/{ACCOUNT}/omnichannelSettings/{REGION_CODE}/lsfProviders/67890",
"regionCode": {REGION_CODE},
"displayName": "LFP Provider 6"
}
],
"nextPageToken": 50
}
ตัวอย่างโค้ดมีดังนี้
package shopping.merchant.samples.accounts.v1beta;
// [START merchantapi_find_lfp_providers]
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.accounts.v1beta.FindLfpProvidersRequest;
import com.google.shopping.merchant.accounts.v1beta.LfpProvider;
import com.google.shopping.merchant.accounts.v1beta.LfpProvidersServiceClient;
import com.google.shopping.merchant.accounts.v1beta.LfpProvidersServiceClient.FindLfpProvidersPagedResponse;
import com.google.shopping.merchant.accounts.v1beta.LfpProvidersServiceSettings;
import com.google.shopping.merchant.accounts.v1beta.OmnichannelSettingName;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;
/** This class demonstrates how to get the Lfp Providers for a given Merchant Center account */
public class FindLfpProvidersSample {
public static void findLfpProviders(Config config, String regionCode)
throws Exception {
// Obtains OAuth token based on the user's configuration.
GoogleCredentials credential = new Authenticator().authenticate();
// Creates service settings using the retrieved credentials.
LfpProvidersServiceSettings lfpProvidersServiceSettings =
LfpProvidersServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
// Gets the account ID from the config file.
String accountId = config.getAccountId().toString();
// Creates parent to identify the omnichannelSetting from which to list all Lfp Providers.
String parent =
OmnichannelSettingName.newBuilder()
.setAccount(accountId)
.setOmnichannelSetting(regionCode)
.build()
.toString();
// Calls the API and catches and prints any network failures/errors.
try (LfpProvidersServiceClient lfpProvidersServiceClient =
LfpProvidersServiceClient.create(lfpProvidersServiceSettings)) {
FindLfpProvidersRequest request =
FindLfpProvidersRequest.newBuilder().setParent(parent).build();
System.out.println("Sending find LFP providers request:");
FindLfpProvidersPagedResponse response = lfpProvidersServiceClient.findLfpProviders(request);
int count = 0;
// Iterates over all the entries in the response.
for (LfpProvider lfpProvider : response.iterateAll()) {
System.out.println(lfpProvider);
count++;
}
System.out.println(String.format("The following count of elements were returned: %d", count));
} catch (Exception e) {
System.out.println("An error has occurred: ");
System.out.println(e);
}
}
public static void main(String[] args) throws Exception {
Config config = Config.load();
// The country you're targeting at.
String regionCode = "{REGION_CODE}";
findLfpProviders(config, regionCode);
}
}
// [END merchantapi_find_lfp_providers]
ลิงก์ผู้ให้บริการ LFP
หากต้องการสร้างพาร์ทเนอร์ทางธุรกิจ LFP ให้ใช้ lfpProviders.LinkLfpProvider
ดังนี้
POST
https://merchantapi.googleapis.com/accounts/v1beta/accounts/{ACCOUNT_ID}/omnichannelSettings/{REGION_CODE}/lfpProviders/{LFP_PROVIDER}:linkLfpProvider
{
"externalAccountId": "{EXTERNAL_ACCOUNT_ID}",
}
แทนที่ค่าต่อไปนี้
{ACCOUNT_ID}
: ตัวระบุที่ไม่ซ้ำกันของบัญชี Merchant Center{LFP_PROVIDER}
: รหัสผู้ให้บริการ LFP ที่แสดงผลในขั้นตอนก่อนหน้า เช่น12345
สำหรับผู้ให้บริการ LFP 1{EXTERNAL_ACCOUNT_ID}
: รหัสบัญชีภายนอกที่ผู้ให้บริการ LFP รู้จักผู้ขาย
ตัวอย่างโค้ดนี้แสดงวิธีลิงก์กับผู้ให้บริการ LFP
package shopping.merchant.samples.accounts.v1beta;
// [START merchantapi_link_lfp_provider]
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.accounts.v1beta.LfpProvidersServiceClient;
import com.google.shopping.merchant.accounts.v1beta.LfpProvidersServiceSettings;
import com.google.shopping.merchant.accounts.v1beta.LinkLfpProviderRequest;
import shopping.merchant.samples.utils.Authenticator;
/** This class demonstrates how to link the Lfp Providers for a given Merchant Center account */
public class LinkLfpProviderSample {
public static void linkLfpProvider(String lfpProviderName, String externalAccountId)
throws Exception {
// Obtains OAuth token based on the user's configuration.
GoogleCredentials credential = new Authenticator().authenticate();
// Creates service settings using the retrieved credentials.
LfpProvidersServiceSettings lfpProvidersServiceSettings =
LfpProvidersServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
// Calls the API and catches and prints any network failures/errors.
try (LfpProvidersServiceClient lfpProvidersServiceClient =
LfpProvidersServiceClient.create(lfpProvidersServiceSettings)) {
LinkLfpProviderRequest request =
LinkLfpProviderRequest.newBuilder()
.setName(lfpProviderName)
.setExternalAccountId(externalAccountId)
.build();
System.out.println("Sending link lfp provider request:");
// Empty response returned on success.
lfpProvidersServiceClient.linkLfpProvider(request);
System.out.println(String.format("Successfully linked to LFP provider: %s", lfpProviderName));
} catch (Exception e) {
System.out.println("An error has occurred: ");
System.out.println(e);
}
}
public static void main(String[] args) throws Exception {
// The name of the lfp provider you want to link, returned from `lfpProviders.findLfpProviders`.
// It's of the form
// "accounts/{account_id}/omnichannelSettings/{omnichannel_settings}/lfpProviders/{lfp_provider}".
String lfpProviderName = "{LFP_PROVIDER_NAME}";
// External account ID by which this merchant is known to the LFP provider.
String externalAccountId = "{EXTERNAL_ACCOUNT_ID}";
linkLfpProvider(lfpProviderName, externalAccountId);
}
}
// [END merchantapi_link_lfp_provider]
``` You can check your LFP status by calling `omnichannelSettings.get` and
checking the `LfpLink` field.
To learn more about how to use LFP, see [Local feeds partnership
API](https://developers.google.com/merchant/api/guides/local-feeds-partnership/overview).