การอัปเดตสินค้าคงคลังที่เพิ่มขึ้น v1

ส่วนนี้อธิบายวิธีส่งการอัปเดตฟีดที่มีกําหนดเวลาให้ Google API การอัปเดตที่เพิ่มขึ้นช่วยให้คุณอัปเดตและลบเอนทิตีในฟีดได้แบบเกือบเรียลไทม์

ฟังก์ชันการทํางานนี้มีไว้สําหรับการอัปเดตที่คุณคาดการณ์ไม่ได้ เช่น การปิดฉุกเฉิน ตามกฎแล้ว การเปลี่ยนแปลงใดๆ ที่ส่งผ่าน API การอัปเดตที่เพิ่มขึ้นควรเป็นการเปลี่ยนแปลงที่ต้องเผยแพร่ภายในระยะเวลาไม่เกิน 1 สัปดาห์ หากการเปลี่ยนแปลงไม่จําเป็นต้องมีผลทันที ให้ใช้การอัปเดตแบบกลุ่มแทน การอัปเดตที่เพิ่มขึ้นการประมวลผลจะใช้เวลาไม่เกิน 5 นาที

ตั้งค่า

ทําตามขั้นตอนต่อไปนี้เพื่อติดตั้งใช้งานเพิ่มเติม

  1. ทําตามขั้นตอนที่ระบุไว้ในหัวข้อสร้างและตั้งค่าโปรเจ็กต์เพื่อสร้างโปรเจ็กต์
  2. ทําตามขั้นตอนที่ระบุไว้ในส่วนตั้งค่าบัญชีบริการเพื่อสร้างบัญชีบริการ โปรดทราบว่าคุณต้องเป็น ""Owner" ของโปรเจ็กต์เพื่อเพิ่มบทบาท "Editor" สําหรับบัญชีบริการ
  3. (ไม่บังคับ แต่แนะนํา) ติดตั้งไลบรารีของไคลเอ็นต์ Google ในภาษาที่คุณต้องการเพื่อความสะดวกในการใช้ OAuth 2.0 เมื่อเรียกใช้ API ตัวอย่างโค้ดด้านล่างใช้ไลบรารีเหล่านี้ ไม่เช่นนั้น คุณจะต้องจัดการการแลกเปลี่ยนโทเค็นด้วยตนเองตามที่อธิบายไว้ในหัวข้อการใช้ OAuth 2.0 เพื่อเข้าถึง Google API

ปลายทาง

หากต้องการแจ้งให้ Google ทราบเกี่ยวกับการอัปเดต ให้ส่งคําขอ HTTP POST ไปยัง API การอัปเดตที่เพิ่มขึ้น และระบุเพย์โหลดของการอัปเดตและการเพิ่ม สคีมาพื้นที่โฆษณาที่คุณใช้จะกําหนดปลายทางที่จะส่งคําขอ

พื้นที่โฆษณาเวอร์ชัน 2

https://actions.googleapis.com/v2/apps/PROJECT_ID/entities/TYPE/ENTITY_ID:push

พื้นที่โฆษณา v1

https://actions.googleapis.com/v2/apps/PROJECT_ID/entities/ENTITY_ID:push

หากต้องการนําเอนทิตีออก ให้ส่งคําขอลบ HTTP ไปยังปลายทางต่อไปนี้ที่สอดคล้องกับสคีมาพื้นที่โฆษณาที่คุณใช้

พื้นที่โฆษณาเวอร์ชัน 2

https://actions.googleapis.com/v2/apps/PROJECT_ID/entities/TYPE/ENTITY_ID?entity.vertical=FOODORDERING&delete_time=DELETE_TIME

พื้นที่โฆษณา v1

https://actions.googleapis.com/v2/apps/PROJECT_ID/entities/ENTITY_ID?entity.vertical=FOODORDERING&delete_time=DELETE_TIME

ในคําขอข้างต้น ให้แทนที่รายการต่อไปนี้

  • PROJECT_ID: รหัสโปรเจ็กต์ Google Cloud ที่เชื่อมโยงกับโปรเจ็กต์ที่สร้างในสร้างและตั้งค่าโปรเจ็กต์
  • TYPE (สคีมาพื้นที่โฆษณา V2 เท่านั้น): ประเภทเอนทิตี (พร็อพเพอร์ตี้ @type) ของออบเจ็กต์ในฟีดข้อมูลที่ต้องการอัปเดต
  • ENTITY_ID: รหัสของเอนทิตีที่รวมอยู่ในเพย์โหลด อย่าลืมเข้ารหัส URL ของรหัสเอนทิตี
  • DELETE_TIME (ลบปลายทางเท่านั้น): ช่องที่ไม่บังคับซึ่งระบุเวลาที่ลบเอนทิตีในระบบของคุณ (ค่าเริ่มต้นคือวันที่ได้รับคําขอ) ค่าเวลาต้องไม่เป็นเวลาในอนาคต เมื่อส่งเอนทิตีผ่านการโทรที่เพิ่มขึ้น การกําหนดเวอร์ชันเอนทิตีจะใช้ช่อง delete_time ในกรณีที่มีการเรียกใช้การลบ จัดรูปแบบค่านี้เป็นyyyy-mm-ddTHH:mm:ssZ

ตัวอย่างเช่น คุณมีโปรเจ็กต์ที่มีรหัส "delivery-provider-id" ที่ใช้สคีมาพื้นที่โฆษณา v2 คุณต้องการเปลี่ยนแปลงร้านอาหารด้วยประเภทเอนทิตีร้านอาหารของ "MenuSection" และรหัสเอนทิตีของ "menuSection_122" ปลายทางของการอัปเดตข้อมูลจะมีลักษณะดังนี้

https://actions.googleapis.com/v2/apps/delivery-provider-id/entities/MenuSection/menuSection_122:push

หากต้องการนําเอนทิตีเดียวกันนี้ออก คุณจะต้องเรียกใช้ HTTP DELETE API นี้

https://actions.googleapis.com/v2/apps/delivery-provider-id/entities/MenuSection/menuSection_122?entity.vertical=FOODORDERING

คําขอแซนด์บ็อกซ์

สําหรับคําขอแซนด์บ็อกซ์ ให้ทําตามคําแนะนําในปลายทางด้านบน แต่ส่งคําขอไปยัง /v2/sandbox/apps/ แทน /v2/apps/ ตัวอย่างเช่น คําขอลบแซนด์บ็อกซ์สําหรับสคีมาพื้นที่โฆษณา v2 มีโครงสร้างดังนี้

https://actions.googleapis.com/v2/sandbox/apps/PROJECT_ID/entities/TYPE/ENTITY_ID?entity.vertical=FOODORDERING&delete_time=DELETE_TIME

การอัปเดตและข้อมูลเพิ่มเติม

ฟีดแบตช์รายวันของคุณควรมีการเปลี่ยนแปลงที่ส่งผ่าน API นี้ด้วย มิเช่นนั้น การอัปเดตแบบกลุ่มจะลบล้างการเปลี่ยนแปลงที่เพิ่มขึ้นของคุณ

เพย์โหลด

คําขอ POST แต่ละรายการต้องมีพารามิเตอร์คําขอ พร้อมด้วยเปย์โหลด JSON ที่มีข้อมูลที่มีโครงสร้างในประเภทเอนทิตีทั้งหมดที่อยู่ในสคีมาของพื้นที่โฆษณา

JSON ควรปรากฏในลักษณะเดียวกับในฟีดกลุ่ม โดยมีความแตกต่างดังต่อไปนี้

  • เนื้อหาเพย์โหลดไม่ควรเกิน 5 MB และเช่นเดียวกับฟีดกลุ่ม เราขอแนะนําให้ตัดการเว้นวรรคเพื่อให้พอดีกับข้อมูลเพิ่มเติม
  • เอนเวโลปมีดังนี้
{
  "entity": {
    "data":"ENTITY_DATA",
    "vertical":"FOODORDERING"
  },
  "update_time":"UPDATE_TIMESTAMP"
}

ในเพย์โหลดข้างต้น ให้แทนที่รายการต่อไปนี้

  • ENTITY_DATA: เอนทิตีในรูปแบบ JSON มีการเรียงลําดับเป็นสตริง เอนทิตี JSON-LD ต้องส่งผ่านเป็นสตริงในช่อง data
  • UPDATE_TIMESTAMP (ไม่บังคับ): การประทับเวลาเมื่อมีการอัปเดตเอนทิตีในระบบของคุณ ค่าเวลาต้องไม่เป็นเวลาในอนาคต การประทับเวลาเริ่มต้นคือเมื่อ Google ได้รับคําขอ เมื่อส่งเอนทิตีผ่านคําขอที่เพิ่มขึ้น การกําหนดเวอร์ชันเอนทิตีจะใช้ช่อง update_time ในกรณีที่มีคําขอเพิ่ม/อัปเดต

การอัปเดตเอนทิตี

ตัวอย่างที่ 1: การอัปเดตร้านอาหาร

สมมติว่าคุณต้องอัปเดตหมายเลขโทรศัพท์ของร้านอาหารโดยด่วน การอัปเดตจะมี JSON ของทั้งร้านอาหาร

ลองดูฟีดแบทช์ที่มีลักษณะดังนี้

{
  "@type": "Restaurant",
  "@id": "restaurant12345",
  "name": "Some Restaurant",
  "url": "https://www.provider.com/somerestaurant",
  "telephone": "+16501234567",
  "streetAddress": "345 Spear St",
  "addressLocality": "San Francisco",
  "addressRegion": "CA",
  "postalCode": "94105",
  "addressCountry": "US",
  "latitude": 37.472842,
  "longitude": -122.217144
}

การอัปเดตที่เพิ่มขึ้นของคุณตาม HTTP POST มีดังต่อไปนี้

POST v2/apps/provider-project/entities/Restaurant/restaurant12345:push
Host: actions.googleapis.com
Content-Type: application/ld+json
{
  "entity": {
    "data": {
      "@type": "Restaurant",
      "@id": "restaurant12345",
      "name": "Some Restaurant",
      "url": "https://www.provider.com/somerestaurant",
      "telephone": "+16501235555",
      "streetAddress": "345 Spear St",
      "addressLocality": "San Francisco",
      "addressRegion": "CA",
      "postalCode": "94105",
      "addressCountry": "US",
      "latitude": 37.472842,
      "longitude": -122.217144
    },
    "vertical": "FOODORDERING"
  }
}

ตัวอย่างที่ 2: การอัปเดตราคารายการในเมนู

สมมติว่าคุณต้องเปลี่ยนแปลงราคาของรายการในเมนู เช่นเดียวกับตัวอย่างที่ 1 การอัปเดตของคุณต้องมี JSON สําหรับเอนทิตีระดับบนสุดทั้งหมด (เมนู) และฟีดใช้สคีมาพื้นที่โฆษณา v1

ลองดูฟีดแบทช์ที่มีลักษณะดังนี้

{
  "@type": "MenuItemOffer",
  "@id": "menuitemoffer6680262",
  "sku": "offer-cola",
  "menuItemId": "menuitem896532",
  "price": 3.00,
  "priceCurrency": "USD"
}

การอัปเดตที่เพิ่มขึ้นของคุณผ่าน POST จะมีลักษณะดังนี้

POST v2/apps/provider-project/entities/MenuItemOffer/menuitemoffer6680262:push
Host: actions.googleapis.com
Content-Type: application/ld+json
{
  "entity": {
    "data": {
      "@type": "MenuItemOffer",
      "@id": "menuitemoffer6680262",
      "sku": "offer-cola",
      "menuItemId": "menuitem896532",
      "price": 1.00,
      "priceCurrency": "USD"
    },
    "vertical": "FOODORDERING"
  }
}

การเพิ่มเอนทิตี

หากต้องการเพิ่มเอนทิตี ให้หลีกเลี่ยงการใช้การอัปเดตพื้นที่โฆษณา โปรดใช้กระบวนการฟีดแบบกลุ่มตามที่อธิบายไว้ในสคีมาพื้นที่โฆษณา v2 แทน

การนําเอนทิตีออก

หากต้องการนําเอนทิตีระดับบนสุดออก ให้ใช้ปลายทางที่มีการแก้ไขเพียงเล็กน้อย และใช้ HTTP DELETE แทน HTTP POST ในคําขอ

อย่าใช้ HTTP DELETE เพื่อนําเอนทิตีย่อยภายในเอนทิตีระดับบนสุดออก เช่น รายการในเมนูในเมนู แต่จะถือว่าลบเอนทิตีย่อยเป็นการอัปเดตเอนทิตีระดับบนสุดที่นําเอนทิตีย่อยออกจากรายการหรือพารามิเตอร์ที่เกี่ยวข้องแทน

ตัวอย่างที่ 1: การลบเอนทิตีระดับบนสุด

พิจารณาสถานการณ์ที่คุณต้องการลบร้านอาหารในฟีดที่ใช้สคีมาพื้นที่โฆษณา v1 คุณต้องลบบริการและเมนูของบริการนั้นด้วย

ตัวอย่างปลายทางสําหรับเอนทิตีเมนูที่มีรหัส "https://www.provider.com/cuisine/menu/nr"

DELETE v2/apps/delivery-provider-id/entities/https%3A%2F%2Fwww.provider.com%2Frestaurant%2Fmenu%2Fnr?entity.vertical=FOODORDERING
Host: actions.googleapis.com

ตัวอย่างปลายทางสําหรับหน่วยงานร้านอาหารที่มีรหัส "https://www.provider.com/cuisine/nr":

DELETE v2/apps/delivery-provider-id/entities/https%3A%2F%2Fwww.provider.com%2Frestaurant%2Fnr?entity.vertical=FOODORDERING
Host: actions.googleapis.com

ตัวอย่างปลายทางสําหรับเอนทิตีบริการที่มีรหัส "https://www.provider.com/Restaurant/service/nr":

DELETE v2/apps/delivery-provider-id/entities/https%3A%2F%2Fwww.provider.com%2Frestaurant%2Fservice%2Fnr?entity.vertical=FOODORDERING
Host: actions.googleapis.com
}

ตัวอย่างที่ 2: การนําเอนทิตีย่อยออก

หากต้องการนําเอนทิตีย่อยออกจากเอนทิตีระดับบนสุด ให้คุณส่งเอนทิตีระดับบนสุดที่มีเอนทิตีย่อยออกจากช่องที่เกี่ยวข้อง ตัวอย่างต่อไปนี้จะถือว่าฟีดใช้สคีมาพื้นที่โฆษณา v1

ตัวอย่างเช่น หากต้องการนําพื้นที่ให้บริการออก ให้อัปเดตบริการโดยนําพื้นที่ให้บริการออกจากรายการ areaServed แล้ว

POST v2/apps/delivery-provider-id/entities/https%3A%2F%2Fwww.provider.com%2Frestaurant%2Fservice%2Fnr:push
Host: actions.googleapis.com
Content-Type: application/ld+json
{
  "entity": {
    // Note: "data" is not serialized as a string in our example for readability.
    "data": {
      "@type": "Service",
      "provider": {
        "@type": "Restaurant",
        "@id": "https://www.provider.com/restaurant/nr"
      },
      "areaServed": [
        {
          "@type": "GeoCircle",
          "geoMidpoint": {
            "@type": "GeoCoordinates",
            "latitude": "42.362757",
            "longitude": "-71.087109"
          },
          "geoRadius": "10000"
        }
        // area2 is removed.
      ]
      ...
    },
    "vertical": "FOODORDERING"
  }
}

โค้ดตอบกลับ API

การเรียกที่สําเร็จไม่ได้หมายความว่าฟีดนั้นถูกต้องหรือถูกต้อง แต่มีการเรียกใช้ API เท่านั้น การเรียกที่สําเร็จจะได้รับรหัสตอบกลับ HTTP 200 และเนื้อหาการตอบกลับที่ว่างเปล่า

{}

สําหรับความล้มเหลว โค้ดตอบกลับ HTTP จะไม่เป็น 200 และเนื้อหาการตอบสนองจะแสดงข้อผิดพลาด

เช่น หากผู้ใช้ตั้งค่า "vertical" ในเอนเวโลปเป็น FAKE_VERTICAL คุณจะได้รับข้อความดังนี้

{
  "error": {
    "code": 400,
    "message": "Invalid value at 'entity.vertical' (TYPE_ENUM), \"FAKE_VERTICAL\"",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.BadRequest",
        "fieldViolations": [
          {
            "field": "entity.vertical",
            "description": "Invalid value at 'entity.vertical' (TYPE_ENUM), \"FAKE_VERTICAL\""
          }
        ]
      }
    ]
  }
}

ตัวอย่างโค้ด

ด้านล่างคือตัวอย่างวิธีใช้ API การอัปเดตที่เพิ่มขึ้นในภาษาต่างๆ ตัวอย่างเหล่านี้ใช้ไลบรารีการตรวจสอบสิทธิ์ของ Google และจะถือว่าฟีดใช้สคีมาพื้นที่โฆษณา v1 สําหรับโซลูชันอื่น โปรดดูที่การใช้ OAuth 2.0 สําหรับแอปพลิเคชันระหว่างเซิร์ฟเวอร์กับเซิร์ฟเวอร์

กําลังอัปเดตเอนทิตี

Node.js

โค้ดนี้ใช้ไลบรารีการตรวจสอบสิทธิ์ของ Google สําหรับ Node.js

const {auth} = require('google-auth-library')
const request = require('request');
// The service account client secret file downloaded from the Google Cloud Console
const serviceAccountJson = require('./service-account.json')
// entity.json is a file that contains the entity data in json format
const entity = require('./entity.json')

const ENTITY_ID = 'restaurant/http://www.provider.com/somerestaurant'
const PROJECT_ID = 'your-project-id'

/**
 * Get the authorization token using a service account.
 */
async function getAuthToken() {
  let client = auth.fromJSON(serviceAccountJson)
  client.scopes = ['https://www.googleapis.com/auth/assistant']
  const tokens = await client.authorize()
  return tokens.access_token;
}

/**
 * Send an incremental update to update or add an entity
 */
async function updateEntity(entityId, entity) {
  const token = await getAuthToken()
  request.post({
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${token}`
    },
    url: `https://actions.googleapis.com/v2/apps/${PROJECT_ID}/entities/${encodeURIComponent(entityId)}:push`,
    body: {
      entity: {
        data: JSON.stringify(entity),
        vertical: 'FOODORDERING',
      }
    },
    json: true
  },
  (err, res, body) => {
    if (err) { return console.log(err); }
    console.log(`Response: ${JSON.stringify(res)}`)
  })
}

updateEntity(ENTITY_ID, entity)

Python

โค้ดนี้ใช้ไลบรารีการตรวจสอบสิทธิ์ของ Google สําหรับ Python

from google.oauth2 import service_account
from google.auth.transport.requests import AuthorizedSession
import json
import urllib

PROJECT_ID = 'your-project-id'
ENTITY_ID = 'restaurant/http://www.provider.com/somerestaurant'
ENDPOINT = 'https://actions.googleapis.com/v2/apps/%s/entities/%s:push' % (
    PROJECT_ID, urllib.quote(ENTITY_ID, ''))

# service-account.json is the service account client secret file downloaded from the
# Google Cloud Console
credentials = service_account.Credentials.from_service_account_file(
    'service-account.json')

scoped_credentials = credentials.with_scopes(
    ['https://www.googleapis.com/auth/assistant'])

authed_session = AuthorizedSession(scoped_credentials)

# Retrieving the entity
update_file = open("entity.json")  #JSON file containing entity data in json format.
data = update_file.read()

# Populating the entity with wrapper
entity = {}
entity['data'] = data #entity JSON-LD serialized as string
entity['vertical'] = 'FOODORDERING'

request = {}
request['entity'] = entity

response = authed_session.post(ENDPOINT, json=request)

print(response.text) #if successful, will be '{}'

Java

รหัสนี้ใช้ไลบรารีการตรวจสอบสิทธิ์ของ Google สําหรับ Java

private static final String PROJECT_ID = "your-project-id";
private static final String ENTITY_ID = "http://www.provider.com/somerestaurant";

/**
 * Get the authorization token using a service account.
 */
private static String getAuthToken() {
  InputStream serviceAccountFile =
      Example.class.getClassLoader().getResourceAsStream("service-account.json");
  ServiceAccountCredentials.Builder credentialsSimpleBuilder =
      ServiceAccountCredentials.fromStream(serviceAccountFile).toBuilder();
  credentialsSimpleBuilder.setScopes(ImmutableList.of("https://www.googleapis.com/auth/assistant"));
  AccessToken accessToken = credentialsSimpleBuilder.build().refreshAccessToken();
  return accessToken.getTokenValue();
}

/**
 * Send an incremental update to update or add an entity.
 * @param entityId The id of the entity to update.
 * @param entity the json of the entity to be updated.
 */
public void updateEntity(String entityId, JSONObject entity) {
  String authToken = getAuthToken();
  String endpoint = String.format(
      "https://actions.googleapis.com/v2/apps/%s/entities/%s:push",
      PROJECT_ID, URLEncoder.encode(entityId, "UTF-8"));
  JSONObject data = new JSONObject();
  data.put("data", entity.toString());
  data.put("vertical", "FOODORDERING");
  JSONObject jsonBody = new JSONObject();
  jsonBody.put("entity", data);
  // Execute POST request
  executePostRequest(endpoint, authToken, jsonBody);
}

การนําเอนทิตีออก

Node.js

โค้ดนี้ใช้ไลบรารีการตรวจสอบสิทธิ์ของ Google สําหรับ Node.js

const {auth} = require('google-auth-library')
const request = require('request');
// The service account client secret file downloaded from the Google Cloud Console
const serviceAccountJson = require('./service-account.json')
// entity.json is a file that contains the entity data in json format
const entity = require('./entity.json')

const ENTITY_ID = 'restaurant/http://www.provider.com/somerestaurant'
const PROJECT_ID = 'your-project-id'

/**
 * Get the authorization token using a service account.
 */
async function getAuthToken() {
  let client = auth.fromJSON(serviceAccountJson)
  client.scopes = ['https://www.googleapis.com/auth/assistant']
  const tokens = await client.authorize()
  return tokens.access_token;
}

/**
 * Send an incremental update to delete an entity
 */
async function deleteEntity(entityId) {
  const token = await getAuthToken()
  request.delete({
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${token}`
    },
    url: `https://actions.googleapis.com/v2/apps/${PROJECT_ID}/entities/${encodeURIComponent(entityId)}?entity.vertical=FOODORDERING`,
    body: {},
    json: true
  },
  (err, res, body) => {
    if (err) { return console.log(err); }
    console.log(`Response: ${JSON.stringify(res)}`)
  })
}

deleteEntity(ENTITY_ID)

Python

โค้ดนี้ใช้ไลบรารีการตรวจสอบสิทธิ์ของ Google สําหรับ Python

from google.oauth2 import service_account
from google.auth.transport.requests import AuthorizedSession
import json
import urllib

# Service config
PROJECT_ID = 'your-project-id'
ENTITY_ID = 'restaurant/http://www.provider.com/somerestaurant'
DELETE_TIME = '2018-04-07T14:30:00-07:00'
ENDPOINT = 'https://actions.googleapis.com/v2/apps/%s/entities/%s?entity.vertical=FOODORDERING&delete_time=%s' % (
    PROJECT_ID, urllib.quote(ENTITY_ID, ''), urllib.quote(DELETE_TIME, ''))

# service-account.json is the service account client secret file downloaded from the
# Google Cloud Console
credentials = service_account.Credentials.from_service_account_file(
    'service-account.json')

scoped_credentials = credentials.with_scopes(
    ['https://www.googleapis.com/auth/assistant'])

authed_session = AuthorizedSession(scoped_credentials)
response = authed_session.delete(ENDPOINT)

print(response.text) #if successful, will be '{}'

Java

รหัสนี้ใช้ไลบรารีการตรวจสอบสิทธิ์ของ Google สําหรับ Java

private static final String PROJECT_ID = "your-project-id";
private static final String ENTITY_ID = "restaurant/http://www.provider.com/somerestaurant";

/**
 * Get the authorization token using a service account.
 */
private static String getAuthToken() {
  InputStream serviceAccountFile = Example.class.getClassLoader().getResourceAsStream("service-account.json");
  ServiceAccountCredentials.Builder credentialsSimpleBuilder =
      ServiceAccountCredentials.fromStream(serviceAccountFile).toBuilder();
  credentialsSimpleBuilder.setScopes(ImmutableList.of("https://www.googleapis.com/auth/assistant"));
  AccessToken accessToken = credentialsSimpleBuilder.build().refreshAccessToken();
  return accessToken.getTokenValue();
}

/**
 * Send an incremental update to delete an entity.
 * @param entityId The id of the entity to delete.
 */
public void deleteEntity(String entityId) {
  String authToken = getAuthToken();
  String endpoint = String.format(
      "https://actions.googleapis.com/v2/apps/%s/entities/%s?entity.vertical=FOODORDERING",
      PROJECT_ID, URLEncoder.encode(entityId, "UTF-8"));
  // Execute DELETE request
  System.out.println(executeDeleteRequest(endpoint, authToken));
}

Use Case

ตัวอย่างการใช้งานต่อไปนี้คือตัวอย่างการอัปเดตที่เพิ่มขึ้น การอัปเดตฟีดแบบสมบูรณ์ และเนื้อหาในการเรียก API ระดับสูง

สถานการณ์ เอนทิตีระดับบนสุด คําอธิบายและเอฟเฟกต์
การปิดใช้บริการ DisabledService

คุณต้องปิดใช้งานบริการด้วยเหตุผลที่ไม่คาดคิด

การอัปเดตที่เพิ่มขึ้น: ส่งเอนทิตี Service ที่ต้องการเปลี่ยนให้ @type เป็น DisabledService แต่เก็บพร็อพเพอร์ตี้อื่นๆ ไว้เหมือนเดิม

ฟีดแบบสมบูรณ์: โปรดอัปเดตเอนทิตีจากฟีดแบบสมบูรณ์เพื่อให้ @type ตั้งค่าเป็น DisabledService ก่อน Google จะดึงข้อมูลครั้งถัดไป มิฉะนั้นเอนทิตีจะเปิดใช้อีกครั้ง

สินค้าบางรายการหมด Menu การอัปเดตที่เพิ่มขึ้น: ส่งเอนทิตี Menu ที่ห่อหุ้มเอาไว้ด้วย offer.inventoryLevel ที่ตั้งค่าเป็น 0 สําหรับ MenuItem ที่ระบุ และข้อมูลอื่นๆ ทั้งหมดจะไม่เปลี่ยนแปลง
การเปลี่ยนแปลงราคาของรายการในเมนู Menu การอัปเดตที่เพิ่มขึ้น: ส่งเอนทิตี Menu ที่ห่อหุ้มไว้ด้วย offer.price ที่กําหนดเป็นราคาที่อัปเดตแล้วสําหรับ MenuItem ที่ระบุ และข้อมูลอื่นๆ ทั้งหมดจะไม่เปลี่ยนแปลง

เพิ่มเอนทิตีระดับบนสุดใหม่

ใช้ได้กับเอนทิตีประเภท Menu, Restaurant และ Service เท่านั้น

Menu, Restaurant, Service

ตัวอย่างเช่น คุณต้องเพิ่มเมนูใหม่ในร้านอาหาร

การอัปเดตที่เพิ่มขึ้น: ส่งเอนทิตีเมนูใหม่พร้อมด้วยเอนทิตีร้านอาหารที่มีช่อง hasMenu อัปเดตให้สอดคล้องกัน

ลบเอนทิตีถาวรอย่างถาวร

ใช้ได้กับเอนทิตีประเภท Menu, Restaurant และ Service เท่านั้น

Menu, Restaurant, Service

การอัปเดตที่เพิ่มขึ้น: ส่งการลบอย่างชัดแจ้ง

ฟีดแบบสมบูรณ์: อย่าลืมนําเอนทิตีออกจากฟีดแบบเต็มก่อน Google จะดึงข้อมูลครั้งถัดไป มิเช่นนั้น ระบบจะเพิ่มเอนทิตีนั้นอีกครั้ง

เพิ่มพื้นที่นําส่งใหม่ใน Service ที่เฉพาะเจาะจง Service ฟีดที่เพิ่มขึ้น: ส่งเอนทิตี Service ที่เป็นปัญหาพร้อมช่องทั้งหมดสมบูรณ์เหมือนที่คุณดําเนินการตามปกติในฟีดทั้งหมด โดยระบุพื้นที่นําส่งใหม่ภายใน areaServed ของ Service
อัปเดตเวลาถึงโดยประมาณใน Service Service ฟีดที่เพิ่มขึ้น: ส่ง Service ให้เหมือนกับในฟีด ยกเว้น hoursAvailable.deliveryHours ที่อัปเดตตามความเหมาะสม
อัปเดตราคาส่งใน Service Service ฟีดที่เพิ่มขึ้น: ส่ง Service แบบเต็มที่มีการอัปเดต offers.priceSpecification.price
อัปเดตเวลานําส่งหรือสั่งกลับบ้านใน Service Service ฟีดที่เพิ่มขึ้น: ส่ง Service ให้เหมือนกับในฟีด ยกเว้น hoursAvailable ที่อัปเดตตามความเหมาะสม
Service (เปลี่ยนยอดสั่งซื้อขั้นต่ํา) Service ฟีดที่เพิ่มขึ้น: ส่ง Service แบบเต็มที่มีการอัปเดต Service.offers.priceSpecification.eligibleTransactionVolume
ลบ MenuItem อย่างถาวร Menu ฟีดที่เพิ่มขึ้น: ส่ง Menu เหมือนกับในฟีด แต่มีการนํา MenuItem นี้ออกจากรายการ hasMenuItems

SLO ในเวลาในการประมวลผลงานแบบกลุ่มและการอัปเดตเพิ่มเติม

เอนทิตีที่เพิ่มผ่านกลุ่มหรือการอัปเดตที่เพิ่มขึ้นจะได้รับการประมวลผลใน 1-2 วัน เอนทิตีที่อัปเดตหรือลบผ่านกลุ่มจะประมวลผลภายใน 2 ชั่วโมง ในขณะที่เอนทิตีที่อัปเดตผ่านการอัปเดตที่เพิ่มขึ้นจะประมวลผลใน 5 นาที เอนทิตีที่ไม่มีอัปเดตจะถูกลบออกใน 7 วัน

คุณสามารถส่ง Google ได้ดังนี้

  • ทํางานแบบกลุ่มหลายรายการในแต่ละวันเพื่อให้พื้นที่โฆษณาเป็นข้อมูลล่าสุดอยู่เสมอ หรือ
  • 1 กลุ่มงานต่อวันและ API ส่วนที่เพิ่มขึ้นเพื่อให้พื้นที่โฆษณามีข้อมูลล่าสุดอยู่เสมอ