Phương thức API

GetReader

GetReader cho phép nhà xuất bản xác thực xem một trong những độc giả có PPID đã biết có liên kết gói thuê bao của họ với Google hay không. Khi sử dụng yêu cầu GET, nhà xuất bản sẽ truy vấn PPID thuộc một Mã ấn bản cụ thể.

Yêu cầu

API REST: Yêu cầu GET

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

Thư viện ứng dụng (Node.js)

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

Phản hồi

Điểm cuối sẽ trả về mã 200 với nội dung JSON chứa created_time của gói thuê bao được liên kết hoặc một lỗi nếu không tìm thấy PPID cho ấn bản. Hãy xem phần lỗi để biết thêm thông tin.

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

GetReaderEntitlements

GetReaderEntitlements cho phép nhà xuất bản truy vấn các quyền đối với một PPID mà nhà xuất bản đã cung cấp trước đó. Bằng cách sử dụng yêu cầu GET, nhà xuất bản yêu cầu các quyền bằng cách cung cấp PPID và Mã ấn bản.

Yêu cầu

API REST: Yêu cầu GET

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

Thư viện ứng dụng (Node.js)

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

Phản hồi

Đối với yêu cầu thành công, định dạng trả về giống với định dạng dùng để lưu trữ các quyền bằng yêu cầu PATCH UpdateReaderEntitlements.

{
  "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"
      }
  ]
}

Đối với những người dùng không có quyền nhưng có PPID được liên kết (ví dụ: quyền đã hết hạn và bị xoá), yêu cầu quyền sẽ trả về một mảng quyền trống trong đối tượng quyền tiêu chuẩn.

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

UpdateReaderEntitlements

UpdateReaderEntitlements được dùng để tạo và cập nhật quyền cho một trình đọc, dựa trên PPID của trình đọc đó.

Trọng tải mẫu này cấp cho trình đọc các quyền PPID 6789 đối với ba mã sản phẩm cho The Daily Bugle: dailybugle.com:basic, dailybugle.com:premiumdailybugle.com:deluxe. Sau đó, khi người đọc 6789 sử dụng các nền tảng của Google cho Tìm kiếm và Khám phá, danh sách "Từ các gói thuê bao của bạn" sẽ hiển thị mọi kết quả có liên quan từ các bài viết trên dailybugle.com được gắn thẻ bằng bất kỳ mã sản phẩm nào trong số này.

Yêu cầu

API REST: Yêu cầu PATCH

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

Nội dung yêu cầu: Để biết thêm thông tin về đối tượng entitlements, hãy tham khảo trang bảng thuật ngữ.

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

Thư viện ứng dụng (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
  });
};

Phản hồi

Sau khi thao tác PATCH thành công, đối tượng entitlements đã lưu sẽ được trả về, ở cùng định dạng với GetReaderEntitlements.

DeleteReader

DeleteReader cho phép nhà xuất bản xoá gói thuê bao đã liên kết theo cách thủ công. Khi sử dụng yêu cầu DELETE, nhà xuất bản sẽ gửi một PPID cho một Mã ấn bản cần xoá.

Trước khi gọi DeleteReader, trước tiên, bạn phải xoá các quyền bằng cách sử dụng UpdateReaderEntitlements với một mảng trống ({ "entitlements": [] }) hoặc đặt tham số force không bắt buộc thành true nếu bạn cần xoá một trình đọc có quyền. Tham số force mặc định là false.

Yêu cầu

API REST: Yêu cầu DELETE

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

Thư viện ứng dụng (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
  });
};

Phản hồi

Thao tác xoá thành công sẽ trả về mã 200 với đối tượng JSON trống {}.

{}