首页 > 解决方案 > 如何修复 Bing Ads 脚本中的“未找到 OAuth 客户端”错误

问题描述

我们在 Bing 上有脚本,可以根据存储在 Google 电子表格中的广告效果和客户目标自动调整广告出价。

最初,我们有一个承包商进行了设置,并且成功了。但我猜承包商正在使用一个临时的谷歌账户,当它消失时,投标人停止了工作。因为它以前确实有效,所以现在可能是我的配置错误导致它崩溃,但承包商向我们指出我已经遵循的步骤无济于事(https://docs.microsoft.com/en-us/advertising /scripts/examples/authenticating-with-google-services#option2)。

已经尝试过的东西

function main() {

  const credentials = {
    accessToken: '',
      client_id: 'REDACTED.apps.googleusercontent.com', // from Google developer console
      client_secret: 'REDACTED', // from Google developer console
      refresh_token: 'REDACTED' // created at https://developers.google.com/oauthplayground
  };

  var access_token = '';
  if (credentials.accessToken) {
    access_token = credentials.accessToken;
  }
  var 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' } });    
  var responseCode = tokenResponse.getResponseCode(); 
  var responseText = tokenResponse.getContentText(); 
  if (responseCode >= 200 && responseCode <= 299) {
    access_token = JSON.parse(responseText)['access_token'];
  }
  throw responseText;  

// use the access token to get client targets from the spreadsheet

JSON 编码的访问令牌是预期的响应,但相反,我们收到带有消息“未找到 OAuth 客户端”的 HTTP 400。

在 OAuth 游乐场 ( https://developers.google.com/oauthplayground )上手动创建访问令牌可以作为权宜之计,但这应该可行。这已经奏效了。:P

标签: google-oauth

解决方案


在这种情况下,修复将 console.developers.google.com > Credentials > OAuth 同意屏幕上的应用程序类型切换到内部而不是公共。

这不在微软提供的步骤中,我不确定这是否会在未来产生影响,但至少我们现在已经脱离了手动过程。


推荐阅读