如何修复Bing Ads脚本中的“找不到OAuth客户端”错误

时间:2019-07-08 09:35:49

标签: google-oauth google-oauth2

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

我们最初由承包商来设置,并且可以正常工作。但是我想承包商在使用临时的Google帐户,竞标者离开后便停止工作了。因为它以前曾经工作过,所以可能是我现在的配置错误正在破坏它,但是承包商向我们指出了我已经遵循的步骤无济于事(https://docs.microsoft.com/en-us/advertising/scripts/examples/authenticating-with-google-services#option2)。

已经尝试过的东西

  • 仔细检查了客户端ID和客户端机密周围是否存在空白
  • 创建了新的客户机密
  • 创建了新的客户ID
  • 确保项目名称,应用程序名称和OAuth客户端ID名称都相同
  • 从头开始创建全新的项目(配置为与上面引用的文章相匹配),以查看是否会带来麻烦
  • 尝试了另一个令牌URL(https://oauth2.googleapis.com/token),该令牌URL出现在从Google下载的client_secret JSON中
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

1 个答案:

答案 0 :(得分:0)

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

那不是Microsoft提供的步骤,而且我不确定这是否会在将来产生影响,但是至少我们暂时不进行手动操作。