প্রকাশকরা মূলত পাঠক এবং তাদের এনটাইটেলমেন্ট পরিচালনার জন্য সার্ভার-সাইড ইন্টিগ্রেশন ব্যবহার করেন। প্রকাশকরা PPID-এর জন্য প্রোডাক্ট আইডি এনটাইটেলমেন্টের Google রেকর্ড আপডেট করার জন্য UpdateReaderEntitlements ব্যবহার করেন।
গুগল ক্লাউড সেটআপ
গুগল ক্লাউডে সাবস্ক্রিপশন লিঙ্কিং কনফিগার করা দুটি প্রধান উপাদান নিয়ে গঠিত:
- একটি প্রদত্ত প্রকল্পের জন্য API সক্ষম করা
- API অ্যাক্সেস করার জন্য একটি পরিষেবা অ্যাকাউন্ট তৈরি করা হচ্ছে
সাবস্ক্রিপশন লিঙ্কিং API সক্ষম করুন
একটি পরিষেবা অ্যাকাউন্ট ব্যবহার করতে এবং পাঠকের এনটাইটেলমেন্ট পরিচালনা করতে, একটি Google ক্লাউড প্রকল্পের জন্য সাবস্ক্রিপশন লিঙ্কিং API সক্ষম করা প্রয়োজন এবং একটি OAuth পরিষেবা অ্যাকাউন্ট সঠিকভাবে কনফিগার করা প্রয়োজন। একটি প্রকল্পের জন্য সাবস্ক্রিপশন লিঙ্কিং API সক্ষম করতে, মেনু -> APIs & Services -> Library থেকে নেভিগেট করুন এবং Subscription Linking অনুসন্ধান করুন, অথবা সরাসরি পৃষ্ঠাটি দেখুন:
https://console.cloud.google.com/apis/library?project=gcp_project_id

চিত্র ১. API লাইব্রেরিতে নেভিগেট করা এবং একটি Google ক্লাউড প্রকল্পের জন্য API সক্ষম করা।
একটি পরিষেবা অ্যাকাউন্ট তৈরি করুন
আপনার অ্যাপ্লিকেশন থেকে সাবস্ক্রিপশন লিঙ্কিং API-তে অ্যাক্সেসের অনুমতি দেওয়ার জন্য পরিষেবা অ্যাকাউন্টগুলি ব্যবহার করা হয়।
- আপনার প্রকল্পের কনসোলের মধ্যে একটি পরিষেবা অ্যাকাউন্ট তৈরি করুন ।
- পরিষেবা অ্যাকাউন্টের জন্য শংসাপত্র তৈরি করুন এবং
credentials.jsonফাইলটি আপনার অ্যাপ্লিকেশনে অ্যাক্সেসযোগ্য একটি নিরাপদ স্থানে সংরক্ষণ করুন। - আপনার তৈরি করা পরিষেবা অ্যাকাউন্টে IAM ভূমিকা "সাবস্ক্রিপশন লিঙ্কিং অ্যাডমিন" প্রদান করুন । পরিষেবা অ্যাকাউন্টের ক্ষমতার উপর সূক্ষ্ম নিয়ন্ত্রণের জন্য, আপনি নিম্নলিখিত টেবিল থেকে উপযুক্ত ভূমিকা নির্ধারণ করতে পারেন।
| ক্ষমতা / ভূমিকা | সাবস্ক্রিপশন লিঙ্কিং অ্যাডমিন | সাবস্ক্রিপশন লিঙ্কিং ভিউয়ার | সাবস্ক্রিপশন লিঙ্কিং এনটাইটেলমেন্ট ভিউয়ার |
|---|---|---|---|
| পাঠকের অধিকার পান | |||
| পাঠকদের আমন্ত্রণ জানান | |||
| পাঠকের অধিকার আপডেট করুন | |||
| পাঠকদের মুছুন |
সাবস্ক্রিপশন লিঙ্কিং API সহ একটি পরিষেবা অ্যাকাউন্ট ব্যবহার করুন
সার্ভিস অ্যাকাউন্টের সাথে সাবস্ক্রিপশন লিঙ্কিং API-তে কলগুলি প্রমাণীকরণ করতে, হয় googleapis ক্লায়েন্ট লাইব্রেরি ব্যবহার করুন (যা স্বয়ংক্রিয়ভাবে access_token অনুরোধগুলি পরিচালনা করে) অথবা সরাসরি REST API দিয়ে অনুরোধগুলিতে স্বাক্ষর করুন। REST API ব্যবহার করলে, আপনাকে প্রথমে একটি access_token ( Google Auth লাইব্রেরির মাধ্যমে অথবা একটি পরিষেবা অ্যাকাউন্ট JWT ব্যবহার করে) পেতে হবে এবং তারপর এটি Authorization হেডারে অন্তর্ভুক্ত করতে হবে।
নিম্নলিখিত ক্লায়েন্ট লাইব্রেরি এবং REST API উদাহরণ উভয়েই getReader() , getReaderEntitlements() , updateReaderEntitlements() এবং deleteReader() কল করার জন্য নমুনা কোড রয়েছে।
পরিষেবা অ্যাকাউন্ট কী এবং অ্যাপ্লিকেশন ডিফল্ট শংসাপত্র (ADC)
সাবস্ক্রিপশন লিঙ্কিং API কল করার জন্য, আপনার একটি পরিষেবা অ্যাকাউন্ট কী থাকতে হবে। আপনার প্রতিষ্ঠানের নীতির কারণে যদি আপনি কোনও পরিষেবা অ্যাকাউন্ট কী রপ্তানি করতে না পারেন, তাহলে আপনি অ্যাপ্লিকেশন ডিফল্ট শংসাপত্র (ADC) পদ্ধতি ব্যবহার করতে পারেন।
gcloud auth application-default login কমান্ড ব্যবহার করে ADC সেট আপ করার জন্য এখানে একটি নমুনা কমান্ড দেওয়া হল:
gcloud config set project [YOUR_PROJECT_ID]
gcloud auth application-default login --impersonate-service-account [YOUR_SERVICE_ACCOUNT_NAME@xxx.iam.gserviceaccount.com]
এই কমান্ডটি পরিষেবা অ্যাকাউন্টের শংসাপত্র ধারণকারী একটি JSON ফাইল তৈরি করে এবং এটি আপনার ফাইল সিস্টেমের একটি সুপরিচিত স্থানে স্থাপন করে। অবস্থানটি আপনার অপারেটিং সিস্টেমের উপর নির্ভর করে:
- লিনাক্স, ম্যাকোস:
$HOME/.config/gcloud/application_default_credentials.json - উইন্ডোজ:
%APPDATA%\gcloud\application_default_credentials.json
আপনার কোডে কী ফাইলের পাথ প্রদান করার প্রয়োজন নেই, কারণ ADC স্বয়ংক্রিয়ভাবে নিজেই শংসাপত্র অনুসন্ধান করে ।
this.auth = new Auth.GoogleAuth({
// keyFile: process.env.KEY_FILE, - You don't need to provide this field
'https://www.googleapis.com/auth/readerrevenue.subscriptionlinking.manage'
],
...
});
ক্লায়েন্ট লাইব্রেরি
এই বিভাগে Node.js-এ googleapis ক্লায়েন্ট লাইব্রেরি কীভাবে ব্যবহার করবেন তা ব্যাখ্যা করা হয়েছে।
নমুনা অনুরোধ
import {readerrevenuesubscriptionlinking_v1, Auth} from 'googleapis';
const subscriptionLinking = readerrevenuesubscriptionlinking_v1.Readerrevenuesubscriptionlinking;
class SubscriptionLinking {
constructor() {
this.auth = new Auth.GoogleAuth({
keyFile: process.env.KEY_FILE,
scopes: [
'https://www.googleapis.com/auth/readerrevenue.subscriptionlinking.manage'
],
})
}
init() {
return new subscriptionLinking(
{version: 'v1', auth: this.auth})
}
}
const subscriptionLinkingApi = new SubscriptionLinking();
const client = subscriptionLinkingApi.init();
/**
* Retrieves details for a specific reader associated with the publication.
* @async
* @param {string} ppid - The Publisher Provided ID (ppid) for the reader.
* @return {Promise<object>} A promise that resolves with the reader's details
* from the API.
*/
async function getReader(ppid) {
const publicationId = process.env.PUBLICATION_ID;
return await client.publications.readers.get({
name: `publications/${publicationId}/readers/${ppid}`,
});
}
/**
* Updates the entitlements for a specific reader.
* @async
* @param {string} ppid - The Publisher Provided ID (ppid) for the reader whose
* entitlements are being updated.
* @return {Promise<object>} A promise that resolves with the result of the
* updated entitlements object.
*/
async function updateReaderEntitlements(ppid) {
const publicationId = process.env.PUBLICATION_ID;
const requestBody = {
/*
Refer to
https://developers.google.com/news/subscribe/subscription-linking/appendix/glossary#entitlements_object
*/
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
});
}
/**
* Retrieves the current entitlements for a specific reader.
* @async
* @param {string} ppid - The Publisher Provided ID (ppid) for the reader.
* @return {Promise<object>} A promise that resolves with the reader's entitlements object.
*/
async function getReaderEntitlements(ppid) {
const publicationId = process.env.PUBLICATION_ID;
return await client.publications.readers.getEntitlements({
name: `publications/${publicationId}/readers/${ppid}/entitlements`
});
}
/**
* Deletes a specific Subscription Linking reader record associated with the publication.
* @async
* @param {string} ppid - The Publisher Provided ID (ppid) for the reader to be deleted.
* @param {boolean=} forceDelete - If true, delete the user even if their
* entitlements are not empty
* @return {Promise<object>} A promise that resolves upon successful deletion
* with an empty object ({})
*/
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
});
}
REST API
যদি আপনি REST API এন্ডপয়েন্ট কল করতে চান, তাহলে Authorization হেডারে সেট করার জন্য accessToken পেতে আপনি যেকোনো পদ্ধতি ব্যবহার করতে পারেন।
১. GoogleAuth লাইব্রেরি ব্যবহার করুন
import { GoogleAuth } from 'google-auth-library';
import credentialJson from 'path_to_your_json_file' with { type: 'json' };
const auth = new GoogleAuth({
credentials: credential_json,
scopes: [
'https://www.googleapis.com/auth/readerrevenue.subscriptionlinking.manage'
]
});
async function getAccessToken() {
const accessToken = await auth.getAccessToken();
return accessToken;
}
২. একটি পরিষেবা অ্যাকাউন্ট JWT ব্যবহার করে একটি access_token তৈরি করুন
import fetch from 'node-fetch';
import jwt from 'jsonwebtoken';
function getSignedJwt() {
/*
Either store the service account credentials string in an environment variable
Or implement logic to fetch it.
*/
const key_file = process.env.CREDENTIALS_STRING
const issueDate = new Date();
const expireMinutes = 60;
const offsetInSeconds = issueDate.getTimezoneOffset() * 60000;
const expireDate = new Date(issueDate.getTime() + (expireMinutes * 60000));
const iat = Math.floor((issueDate.getTime() + offsetInSeconds) / 1000);
const exp = Math.floor((expireDate.getTime() + offsetInSeconds) / 1000);
const token = {
iss: key_file.client_email,
iat,
exp,
aud: 'https://oauth2.googleapis.com/token',
scope:'https://www.googleapis.com/auth/readerrevenue.subscriptionlinking.manage',
}
return jwt.sign(token, key_file.private_key, {
algorithm: 'RS256',
keyid: key_file.private_key_id,
})
}
async function getAccessToken(signedJwt) {
let body = new URLSearchParams();
body.set('grant_type', 'urn:ietf:params:oauth:grant-type:jwt-bearer');
body.set('assertion', signedJwt);
const response = await fetch('https://oauth2.googleapis.com/token', {
method: 'POST',
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
body
})
const accessResponse = await response.json();
return accessResponse.access_token;
}
Google Auth লাইব্রেরির সাথে REST API কলের জন্য নমুনা কোড
import { GoogleAuth } from 'google-auth-library';
import fetch from 'node-fetch'
import credentialJson from 'path_to_your_json_file' with { type: 'json' };
const BASE_SUBSCRIPTION_LINKING_API_URL='https://readerrevenuesubscriptionlinking.googleapis.com/v1';
const publicationId = process.env.PUBLICATION_ID
const auth = new GoogleAuth({
credentials: credentialJson,
scopes: [
'https://www.googleapis.com/auth/readerrevenue.subscriptionlinking.manage'
]
});
async function getAccessToken() {
const accessToken = await auth.getAccessToken();
return accessToken;
}
/**
* Retrieves details for a specific reader associated with the publication.
* @async
* @param {string} ppid - The Publisher Provided ID (ppid) for the reader.
* @return {object} reader json for the given ppid
*/
async function getReader(ppid) {
const endpoint = `${BASE_SUBSCRIPTION_LINKING_API_URL}/publications/${publicationId}/readers/${ppid}`;
const accessToken = await getAccessToken();
const response = await fetch(endpoint, {
method: 'GET',
headers: {
Authorization: `Bearer ${accessToken}`,
},
});
const reader = await response.json();
return reader;
}
/**
* Updates the entitlements for a specific reader.
* @async
* @param {string} ppid - The Publisher Provided ID (ppid) for the reader.
* @return {object} the updated entitlements object in json.
*/
async function updateReaderEntitlements(ppid) {
const endpoint = `${BASE_SUBSCRIPTION_LINKING_API_URL}/publications/${publicationId}/readers/${ppid}/entitlements`;
const requestBody = {
/*
Refer to
https://developers.google.com/news/subscribe/subscription-linking/appendix/glossary#entitlements_object
*/
entitlements : [{
product_id: `${publicationId}:basic`,
subscription_token: 'abc1234',
detail: 'This is our basic plan',
expire_time: '2025-10-21T03:05:08.200564Z'
}]
};
const response = await fetch(endpoint, {
method: 'PATCH',
headers: {
Authorization: `Bearer ${accessToken}`,
'Content-Type': 'application/json',
},
body: JSON.stringify(requestBody)
})
const updatedEntitlements = await response.json();
return updatedEntitlements;
}
/**
* Retrieves the current entitlements for a specific reader.
* @async
* @param {string} ppid - The Publisher Provided ID (ppid) for the reader.
* @return {object} the reader's entitlements object in json.
*/
async function getReaderEntitlements(ppid) {
const endpoint = `${BASE_SUBSCRIPTION_LINKING_API_URL}/publications/${publicationId}/readers/${ppid}/entitlements`;
const accessToken = await getAccessToken();
const response = await fetch(endpoint, {
method: 'GET',
headers: {
Authorization: `Bearer ${accessToken}`,
},
});
const entitlements = await response.json();
return entitlements;
}
/**
* Deletes a specific Subscription Linkikng reader record associated with the publication.
* @async
* @param {string} ppid - The Publisher Provided ID (ppid) for the reader.
* @param {boolean=} forceDelete - If true, delete the user even if their
* entitlements are not empty
* @return {object} returns an empty object ({}) if the delete operation is successful
*/
async function deleteReader(ppid, forceDelete = false) {
const endpoint = `${BASE_SUBSCRIPTION_LINKING_API_URL}/publications/${publicationId}/readers/${ppid}?force=${forceDelete}`;
const response = await fetch(endpoint, {
method: 'DELETE',
headers: {
Authorization: `Bearer ${accessToken}`,
}
});
const result = await response.json();
return result;
}