这回波是叉子 https://github.com/thewizarodofoz/google-ad-manager-api 页面存档备份,存于互联网档案馆 为不同的游戏服务更新依赖性、功能并添加打字功能.
我们试图保持整体结构的完整,但出于可读性原因,我们把授权移到自己的一步. 检出第2步为更改,第3步为去除代码.
BN Google 代理管理器节点 Api
谷歌的现代包装 代理经理 API。 。 。 .
特征
- 基于承诺-使用承诺或同步/等待
- 对认证机制没有意见
- 已打入( TypeScript-ish)
安装
npm i @BonnierNews/bn-google-ad-manager-api
使用量
步骤一
以任何你喜欢的方式获取访问符,例如使用 谷歌 Auth 库是因为 JSON 网络键 机制:
const { auth } = require("google-auth-library");
const keys = {
type: "service_account",
project_id: "...",
private_key_id: "...",
private_key: "...",
client_email: "...",
client_id: "...",
auth_uri: "https://accounts.google.com/o/oauth2/auth",
token_uri: "https://oauth2.googleapis.com/token",
auth_provider_x509_cert_url: "https://www.googleapis.com/oauth2/v1/certs",
client_x509_cert_url: "...",
};
const client = auth.fromJSON(keys);
client.scopes = ["https://www.googleapis.com/auth/dfp"];
await client.authorize();
步骤二:
创建客户端, 并授权它使用第 1 级的 Google 认证证书符号 :
import { DFPClient, GAMClient } from "@BonnierNews/bn-google-ad-manager-api";
// To maintain backwards compatability we keep the DFP client intact with the option to use our own client.
// Both have the same functions
const dfpClient = new DFPClient();
await dfpClient.authorize({ networkCode: "...", apiVersion: "v201805", accessToken: client.credentials.access_token });
// or with gamClient
const gamClient = new GAMClient();
await gamClient.authorize({ networkCode: "...", apiVersion: "v201805", accessToken: client.credentials.access_token });
步骤 三
使用客户端创建服务.
const lineItemService = await dfpClient.getService("LineItemService");
// or
const lineItemService = await gamClient.getService("LineItemService");
步骤4
启动服务方法:
const res = await lineItemService.getLineItemsByStatement({
filterStatement: {
query: "WHERE name LIKE 'prebid%'",
},
});
console.log(res.results[0].id);
页:1
- 这个 代理经理 API 返回一个
rval字段用于每种方法的引用. 为了方便我们,这个一揽子方案将恢复该领域的内容. 例如,援引LineItemService.getLineItemsByStatement将返回 aLineItemPage对象直接. - Google 认证令牌有过期日期,需要以某种方式更新或刷新. 由于认证管理不属于此软件包的范畴, 请确保总是将新代号传递给使用
service.setToken。 。 。 .