google-oauth - 如何修复 Bing Ads 脚本中的“未找到 OAuth 客户端”错误
问题描述
我们在 Bing 上有脚本,可以根据存储在 Google 电子表格中的广告效果和客户目标自动调整广告出价。
最初,我们有一个承包商进行了设置,并且成功了。但我猜承包商正在使用一个临时的谷歌账户,当它消失时,投标人停止了工作。因为它以前确实有效,所以现在可能是我的配置错误导致它崩溃,但承包商向我们指出我已经遵循的步骤无济于事(https://docs.microsoft.com/en-us/advertising /scripts/examples/authenticating-with-google-services#option2)。
已经尝试过的东西
- 仔细检查客户端 ID 和客户端密码周围的错误空格
- 创建了新的客户端机密
- 创建了新的客户 ID
- 确保项目名称、应用程序名称和 OAuth 客户端 ID 名称都相同
- 从头开始创建全新的项目(配置为与上面引用的文章相匹配),看看这是否会让一些事情变得松散
- 尝试了从 Google 下载的 client_secret JSON 中出现的不同令牌 URL ( https://oauth2.googleapis.com/token )
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
解决方案
在这种情况下,修复将 console.developers.google.com > Credentials > OAuth 同意屏幕上的应用程序类型切换到内部而不是公共。
这不在微软提供的步骤中,我不确定这是否会在未来产生影响,但至少我们现在已经脱离了手动过程。
推荐阅读
- python-3.x - 如何在运行后删除所有 Xcom?
- php - 返回用户姓名和姓氏的方法以及根据用户是否成人返回布尔值的方法
- protobuf-net - 是否可以将默认序列化程序设置为 protobuf-net 中的预编译序列化程序?
- javascript - 如何在javascript中存储256位十六进制
- sql - 首次接触解决
- android - 用于地理位置跟踪的前台或后台服务
- java - 如何通过 java 代码执行“java”命令?
- java - 如何从 Maven 的命令行捕获参数
- python - python中未设置变量的简单var赋值
- php - 元素中组的回显 ACF 子字段