首页 > 解决方案 > 如何使用 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 知识的人对如何进行此集成有任何想法或提示。

谢谢

标签: google-apps-scriptoauth-2.0integrationgoogle-oauth

解决方案


推荐阅读