google-apps-script - 如何使用 Google 应用脚本集成 Google Ads Manager (GAM)
问题描述
我需要在 GAM 的 API 和 Google App Script 之间创建一个集成。为此,我只有带有凭据的 JSON,格式如下:
{
"type": "service_account",
"project_id": "...",
"private_key_id": "...",
"private_key": "-----BEGIN PRIVATE KEY-----...-----END PRIVATE KEY-----\n",
"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": "..."
}
目前,我正在尝试使用凭证中的信息创建 OAuth 2.0:
const auth = OAuth2.createService("GAM")
.setAuthorizationBaseUrl(credential.auth_uri)
.setTokenUrl(credential.token_uri)
.setPrivateKey(credential.private_key)
.setIssuer(credential.client_email)
.setClientId(credential.client_id)
.setPropertyStore(PropertiesService.getScriptProperties())
.setParam('access_type', 'offline')
.setScope(['https://www.googleapis.com/auth/dfp']);
并使用“UrlFetchApp.fetch”向 API 发出请求:
const url = "https://dns.googleapis.com/dns/v1/projects/" + credential.project_id;
const options = {
'method' : 'get',
'contentType': 'application/json',
headers: {
Authorization: 'Bearer ' + getToken
},
'muteHttpExceptions': true,
};
const response = UrlFetchApp.fetch(url, options);
const data = response.getContentText();
我正在尝试这样做,但我还没有结果,不知道出了什么问题。如果有使用 Google App Script 和/或 Google Ads Manager 知识的人对如何进行此集成有任何想法或提示。
谢谢
解决方案
推荐阅读
- r - 创建具有一行和多列的数据框
- selenium - 在 xpath 中使用 css 类样式属性(不是内联样式)?
- .net - 无法在 .net 3.5 项目上安装 woocommercenet
- php - 使用 PHP,如何在较长的字符串中搜索以特定内容开头和结尾的较短字符串?
- ios - 对于 HEIC 图像,获取点的像素颜色需要很长时间
- tfs - TFS 发布代码覆盖结果任务与 OpenCover 不工作
- sql-server - 根据包含“从”和“到”日期的字段确定未涵盖的天数
- c# - 如何在 razor 中创建自定义 @using 代码块
- error-handling - julia:在控制流中显示“catch”错误
- javascript - 我用什么代替 .change 来显示或不显示基于列表值的框