node.js - 将 Adwords 帐户链接到 MCC 帐户、Adwords API、NodeJs
问题描述
我正在尝试使用Node Adwords NPM 包将 Adwords 帐户链接到 MCC 帐户
- 我对两个帐户都有MANAGER/Admin 访问权限(不同的电子邮件)
- 我在谷歌控制台开发人员上创建了一个项目/应用程序,以使用 MCC 电子邮件用户获取
Client_ID和Client_Secret 。 - 我使用上述凭据恢复了访问令牌/刷新令牌
- 现在使用具有标准访问、Client_ID、Client_Secret、Refresh_Token、Access_Token和ClientCustomerID的生产开发人员令牌
我使用Passport OAuth2 SSO 流程获得了刷新令牌。
客户应该通过我们的网络应用程序登录,一旦成功登录,我们会收到他的 access_token 和 refresh_token,然后我们邀请他由我们的 MCC 帐户管理,但是请求失败并显示未经授权。
我究竟做错了什么 ?
1-SOAP 响应
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<ns2:ResponseHeader xmlns:ns2="https://adwords.google.com/api/adwords/mcm/v201802" xmlns="https://adwords.google.com/api/adwords/cm/v201802">
<requestId>000579c3b56e65c00a85859ae60c1a37</requestId>
<serviceName>ManagedCustomerService</serviceName>
<methodName>mutateLink</methodName>
<operations>1</operations>
<responseTime>173</responseTime>
</ns2:ResponseHeader>
</soap:Header>
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>[ManagedCustomerServiceError.NOT_AUTHORIZED @ operations[0]]</faultstring>
<detail>
<ns2:ApiExceptionFault xmlns:ns2="https://adwords.google.com/api/adwords/mcm/v201802" xmlns="https://adwords.google.com/api/adwords/cm/v201802">
<message>[ManagedCustomerServiceError.NOT_AUTHORIZED @ operations[0]]</message>
<ApplicationException.Type>ApiException</ApplicationException.Type>
<errors xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:ManagedCustomerServiceError">
<fieldPath>operations[0]</fieldPath>
<fieldPathElements>
<field>operations</field>
<index>0</index>
</fieldPathElements>
<trigger />
<errorString>ManagedCustomerServiceError.NOT_AUTHORIZED</errorString>
<ApiError.Type>ManagedCustomerServiceError</ApiError.Type>
<ns2:reason>NOT_AUTHORIZED</ns2:reason>
</errors>
</ns2:ApiExceptionFault>
</detail>
</soap:Fault>
</soap:Body>
</soap:Envelope>
2- 节点示例代码
const adwordsUser = new AdwordsUser({
developerToken: 'DEVToken',
userAgent: 'App Name',
client_id: 'CLIENT_ID',
client_secret: 'CLIENT_SECRET',
refresh_token: 'REFRESH_TOKEN',
clientCustomerId: 'AdwordsAccountID'
});
customerService = adwordsUser.getService('ManagedCustomerService', null);
customerService.mutateLink({
operations: [
{
operator: 'ADD',
operand: {
managerCustomerId: 'MCCAccountCustomerID',
clientCustomerId: 'AdwordsAccountID',
linkStatus: 'PENDING'
}
}
]
}, function (err, result) {
if (err) console.log(err)
console.log(result)
})
解决方案
要从 MCC 向 adwords 帐户发送邀请:
您必须在 MCC 中使用相同的管理员/经理创建 client_id 和 client_secret
使用具有 adwords 范围的同一用户生成 OAuth2 令牌(您的 MCC 经理)
使用您的 MCC 帐户拨打电话(您可以使用任何 MCC 的开发者令牌,没关系)
const adwordsUser = new AdwordsUser({
developerToken: 'DEVToken',
userAgent: 'App Name',
client_id: 'CLIENT_ID',
client_secret: 'CLIENT_SECRET',
refresh_token: 'REFRESH_TOKEN',
});
adwordsUser.credentials.clientCustomerId = 'MCCAccountCustomerID';
customerService = adwordsUser.getService('ManagedCustomerService', null);
operations: [{
operator: 'ADD',
operand: {
managerCustomerId: 'MCCAccountCustomerID',
clientCustomerId: 'AdwordsAccountID', // Account to invite
linkStatus: 'PENDING'
}
}]
在客户账户中接受邀请:
使用客户端用户生成 OAuth2 令牌
使用客户的 adwords 帐户、活动链接状态和 SET 作为操作员进行呼叫
const adwordsUser = new AdwordsUser({
developerToken: 'DEVToken',
userAgent: 'App Name',
client_id: 'CLIENT_ID',
client_secret: 'CLIENT_SECRET',
refresh_token: 'REFRESH_TOKEN',
});
adwordsUser.credentials.clientCustomerId = 'AdwordsAccountID'; // invited account id
customerService = adwordsUser.getService('ManagedCustomerService', null);
operations: [{
operator: 'SET',
operand: {
managerCustomerId: 'MCCAccountCustomerID',
clientCustomerId: 'AdwordsAccountID',
linkStatus: 'ACTIVE'
}
}]
推荐阅读
- multithreading - 如何在 Rust 中的线程之间共享不可变数据?
- python-3.x - 如何覆盖父类的init方法,并使用super调用祖父init,而无需编辑父类?(蟒蛇3)
- python - 将加载条的百分比四舍五入,但将 [99-100) 调整为 99%,将 (0, 1] 调整为 1%
- php - 如何在可能具有 % 的格式字符串的一部分中转义 sprintf 说明符
- android - firebase 实时数据库规则:读,写 = true。将使用我的应用程序的人可以破解我的 Firebase 帐户吗?
- json - 如何使用 json.NewDecoder 在 Go 中处理 json 响应中的空值
- python - 如何检查给定的ocject是否是内置编译生成的“代码”实例?
- android - 证明 2 个移动设备彼此靠近
- c# - 为什么当我尝试从具有多对多关系的表中获取数据时出现异常
- python - 如何在python中使用阶乘运算符?例如:- 4!预期输出为 24