API 方法

GetReader

GetReader 可讓發布商驗證讀者是否已將訂閱方案連結至 Google,前提是讀者必須有已知的 PPID。發布商會使用 GET 要求,查詢特定發布 ID 所屬的 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}`,
  });
};

回應

如果找到出版物的 PPID,端點會傳回 200,並在 JSON 主體中包含連結訂閱項目的 created_time;如果找不到,則會傳回錯誤。詳情請參閱錯誤一節

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

GetReaderEntitlements

GetReaderEntitlements可讓發布商查詢先前提供的 PPID 授權。發布商使用 GET 要求,提供 PPID 和出版品 ID 來要求權利。

要求

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) 三個《號角日報》產品 ID 的權利:dailybugle.com:basicdailybugle.com:premiumdailybugle.com:deluxe。當讀者 6789 後續使用 Google 搜尋和探索服務時,「你的訂閱內容」清單會顯示任何相關結果,包括標記這些產品 ID 的 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 要求,提交要刪除的出版物 ID 的 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 物件 {}

{}