เมธอดของ API

GetReader

GetReader ช่วยให้ผู้เผยแพร่โฆษณาสามารถตรวจสอบได้ว่าผู้อ่านที่มี PPID ที่ทราบได้ลิงก์การสมัครใช้บริการกับ Google หรือไม่ เมื่อใช้GETคำขอ ผู้เผยแพร่โฆษณาจะค้นหา PPID ที่เป็นของรหัสสิ่งพิมพ์ที่เฉพาะเจาะจง

ส่งคำขอ

REST API: GET คำขอ

https://readerrevenuesubscriptionlinking.googleapis.com/v1/publications/publicationId/readers/ppid

ไลบรารีของไคลเอ็นต์ (Node.js)

async function getReader(ppid) {
  const publicationId = process.env.PUBLICATION_ID;
  return await client.publications.readers.get({
    name: `publications/${publicationId}/readers/${ppid}`,
  });
};

การตอบกลับ

ปลายทางจะแสดงผล 200 พร้อมเนื้อหา JSON ที่มี created_time ของการติดตามที่ลิงก์ หรือข้อผิดพลาดหากไม่พบ PPID สำหรับสิ่งพิมพ์ ดูข้อมูลเพิ่มเติมได้ในส่วนข้อผิดพลาด

{
  "name": "publications/CAowqfCKCw/readers/22553",
  "createTime": "2025-07-30T18:26:58.050224Z",
  "publicationId": "CAowqfCKCw",
  "ppid": "22553",
  "originatingPublicationId": "CAowqfCKCw"
}

GetReaderEntitlements

GetReaderEntitlements ช่วยให้ผู้เผยแพร่โฆษณาสอบถามสิทธิ์สำหรับ PPID ที่ผู้เผยแพร่โฆษณาเคยให้ไว้ได้ โดยใช้คำขอ GET ผู้เผยแพร่โฆษณา จะขอสิทธิ์โดยระบุ PPID และรหัสสิ่งพิมพ์

ส่งคำขอ

REST API: GET คำขอ

https://readerrevenuesubscriptionlinking.googleapis.com/v1/publications/publicationId/readers/ppid/entitlements

ไลบรารีของไคลเอ็นต์ (Node.js)

async function getReaderEntitlements(ppid) {
  const publicationId = process.env.PUBLICATION_ID;
  return await client.publications.readers.getEntitlements({
    name: `publications/${publicationId}/readers/${ppid}/entitlements`
  });
};

การตอบกลับ

หากคำขอสำเร็จ รูปแบบการตอบกลับจะเหมือนกับรูปแบบที่ใช้ในการ จัดเก็บสิทธิ์ด้วยคำขอ UpdateReaderEntitlements PATCH

{
  "name": "publications/dailybugle.com/readers/6789/entitlements",
  "entitlements": [
      {
        "product_id": "dailybugle.com:basic",
        "subscription_token": "dnabhdufbwinkjanvejskenfw",
        "detail": "This is our basic plan",
        "expire_time": "2022-08-19T04:53:40+00:00"
      },
      {
        "product_id": "dailybugle.com:premium",
        "subscription_token": "wfwhddgdgnkhngfw",
        "detail": "This is our premium plan",
        "expire_time": "2022-07-19T04:53:40+00:00"
      },
      {
        "product_id": "dailybugle.com:deluxe",
        "subscription_token": "fefcbwinkjanvejfefw",
        "detail": "This is our deluxe plan",
        "expire_time": "2022-08-20T04:53:40+00:00"
      }
  ]
}

สำหรับผู้ใช้ที่ไม่มีสิทธิ์ แต่มี PPID ที่ลิงก์ไว้ (เช่น สิทธิ์ที่หมดอายุและถูกล้างข้อมูล) คำขอสิทธิ์จะ แสดงผลอาร์เรย์สิทธิ์ที่ว่างเปล่าเป็นส่วนหนึ่งของออบเจ็กต์สิทธิ์มาตรฐาน

{
  "name": "publications/dailybugle.com/readers/6789/entitlements"
}

UpdateReaderEntitlements

UpdateReaderEntitlements ใช้เพื่อสร้างและอัปเดตการให้สิทธิ์สำหรับผู้อ่านโดยอิงตาม PPID

เพย์โหลดตัวอย่างนี้ให้สิทธิ์ผู้อ่านที่มี PPID 6789 ในรหัสผลิตภัณฑ์ 3 รายการสำหรับ The Daily Bugle ได้แก่ dailybugle.com:basic, dailybugle.com:premium และ dailybugle.com:deluxe เมื่อผู้อ่าน 6789 ใช้แพลตฟอร์มของ Google สำหรับ Search และ Discover ในภายหลัง รายการ "จากข้อมูลที่คุณติดตาม" จะแสดงผลลัพธ์ที่เกี่ยวข้อง จากบทความใน dailybugle.com ที่ติดแท็กรหัสผลิตภัณฑ์เหล่านี้

ส่งคำขอ

REST API: PATCH คำขอ

https://readerrevenuesubscriptionlinking.googleapis.com/v1/publications/publicationId/readers/ppid/entitlements

เนื้อหาของคำขอ: ดูข้อมูลเพิ่มเติมเกี่ยวกับออบเจ็กต์ entitlements ได้ที่หน้าพจนานุกรม

{
  entitlements : [{
    product_id: `${publicationId}:basic`,
    subscription_token: 'abc1234',
    detail: 'This is our basic plan',
    expire_time: '2025-10-21T03:05:08.200564Z'
  }]
}

ไลบรารีของไคลเอ็นต์ (Node.js)

async function updateReaderEntitlements(ppid) {
  const publicationId = process.env.PUBLICATION_ID;
  const requestBody = {
    entitlements : [{
      product_id: `${publicationId}:basic`,
      subscription_token: 'abc1234',
      detail: 'This is our basic plan',
      expire_time: '2025-10-21T03:05:08.200564Z'
    }]
  };
  return await client.publications.readers.updateEntitlements({
    name: `publications/${publicationId}/readers/${ppid}/entitlements`,
    requestBody
  });
}

การตอบกลับ

เมื่อดำเนินการ PATCH สำเร็จ ระบบจะแสดงออบเจ็กต์ entitlements ที่บันทึกไว้ในรูปแบบเดียวกับ GetReaderEntitlements

DeleteReader

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

ก่อนเรียกใช้ DeleteReader คุณต้องลบสิทธิ์ก่อนโดยใช้ UpdateReaderEntitlements ที่มีอาร์เรย์ว่าง ({ "entitlements": [] }) หรือตั้งค่าพารามิเตอร์ force ที่ไม่บังคับเป็น true หากต้องการลบผู้อ่านที่มีสิทธิ์ พารามิเตอร์ force มีค่าเริ่มต้นเป็น false

ส่งคำขอ

REST API: DELETE คำขอ

https://readerrevenuesubscriptionlinking.googleapis.com/v1/publications/publicationId/readers/ppid?force={boolean}

ไลบรารีของไคลเอ็นต์ (Node.js)

async function deleteReader(ppid, forceDelete = false) {
  const publicationId = process.env.PUBLICATION_ID;
  return await client.publications.readers.delete({
    name: `publications/${publicationId}/readers/${ppid}`,
    force: forceDelete
  });
}

การตอบกลับ

การลบที่สำเร็จจะแสดงรหัส 200 พร้อมออบเจ็กต์ JSON ว่าง {}

{}