Bing Ads 脚本可使用 Google 表格更改多个帐户的共享广告系列预算

问题描述 投票:0回答:2

我正在运行一个 Google Ads 脚本来更改广告系列预算,但在 Bing Ads 中实施相同的脚本对我来说更加困难。我在将 Google 表格与 Bing Ads 脚本连接的代码时遇到问题。我获得了 clientId、clientSecret 和刷新令牌来授权 Bing 中的 Google 服务,但正在努力编写允许脚本读取我的 Google Sheets 文件的代码。

我附加了一些负责将 Google Sheets 文件连接到 Bing 脚本的代码。它应该允许它读取其内容,然后将其更改为我在该文件中提供的任何值。

const credentials = {
      accessToken: '', // not sure if i needed it if I got refresh token
      clientId: 'HIDDEN',
      clientSecret: 'HIDDEN',
      refreshToken: 'HIDDEN'
  };

  function main() {

var SPREADSHEET_URL = 'HIDDEN';

var GoogleApis;
  (function (GoogleApis) {
      GoogleApis.readSheetsService = credentials => readService("https://sheets.googleapis.com/$discovery/rest?version=v4", credentials);
       
      // Creation logic based on https://developers.google.com/discovery/v1/using#usage-simple
      function readService(SPREADSHEET_URL, credentials) {
          const content = UrlFetchApp.fetch(SPREADSHEET_URL).getContentText();
          const discovery = JSON.parse(content);
          const accessToken = getAccessToken(credentials);
          const standardParameters = discovery.parameters;
      }

  function getAccessToken(credentials) {
      if (credentials.accessToken) {
          return credentials.accessToken;
      }
      const tokenResponse = UrlFetchApp.fetch('https://www.googleapis.com/oauth2/v4/token', { method: 'post', contentType: 'application/x-www-form-urlencoded', muteHttpExceptions: true, payload: { client_id: credentials.clientId, client_secret: credentials.clientSecret, refresh_token: credentials.refreshToken, grant_type: 'refresh_token' } });
      const responseCode = tokenResponse.getResponseCode();
      const responseText = tokenResponse.getContentText();
      if (responseCode >= 200 && responseCode <= 299) {
          const accessToken = JSON.parse(responseText)['access_token'];
          return accessToken;
      }
      throw new Error(responseText);
   })(GoogleApis || (GoogleApis = {}));

它在代码的最后一行抛出语法错误: })(GoogleApis || (GoogleApis = {}));

但我认为还有更多。

google-play-services google-sheets-api bing bing-ads-api
2个回答
1
投票

请尝试在 main() 之外使用

var GoogleApis
声明,如本示例所示:https://learn.microsoft.com/en-us/advertising/scripts/examples/calling-google-services

我希望这有帮助。


-1
投票

你有没有弄清楚这一点?我被困在同样的事情上。

© www.soinside.com 2019 - 2024. All rights reserved.