การอัปเดตพื้นที่โฆษณาที่เพิ่มขึ้น v1

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

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

ตั้งค่า

หากต้องการติดตั้งอัปเดตแบบค่อยเป็นค่อยไป ให้ทำตามขั้นตอนต่อไปนี้

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

ปลายทาง

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

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

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 DELETE ไปยังปลายทางต่อไปนี้ที่สอดคล้องกับสคีมาพื้นที่โฆษณาที่คุณใช้

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

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/restaurant/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/merchant/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/merchant/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 และเนื้อหาการตอบสนองจะบ่งชี้ถึงข้อผิดพลาดที่เกิดขึ้น

ตัวอย่างเช่น หากผู้ใช้ตั้งค่า "แนวตั้ง" ในเอนเวโลปเป็น 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 ที่เพิ่มขึ้นเพื่อให้พื้นที่โฆษณาอัปเดตอยู่เสมอ