API 方法

GetReader

GetReader 允许发布商验证具有已知 PPID 的读者是否已将其订阅与 Google 相关联。发布商可以使用 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}`,
  });
};

响应

该端点将返回 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 和出版物 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 搜索和 Google 探索平台时,“订阅内容”列表中会显示 dailybugle.com 上标记有上述任一商品 ID 的文章的相关结果。

请求

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 之前,您必须先使用空数组 ({ "entitlements": [] }) 通过 UpdateReaderEntitlements 删除授权,或者将可选的 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 对象 {}

{}