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
授權授予讀者,讓讀者可以存取 The Daily Bugle 的三個產品 ID:dailybugle.com:basic
、dailybugle.com:premium
和 dailybugle.com:deluxe
。當讀者 6789
之後使用 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
之前,您必須先使用 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 物件 {}
。
{}