Link Adwords 帐户到 MCC 帐户,Adwords API,NodeJs

Link Adwords Account to MCC Account, Adwords API, NodeJs

我正在尝试使用 Node Adwords NPM 包

将 Adwords 帐户link 添加到 MCC 帐户
  1. 我可以MANAGER/Admin 访问 两个帐户(不同的电子邮件)
  2. 我在 google 控制台开发人员上创建了一个 project/application 来获得
    Client_IDClient_Secret 使用 MCC 电子邮件用户。
  3. 我使用上述凭据恢复了访问 Token/Refresh 令牌
  4. 现在使用具有标准访问权限的生产开发人员令牌,Client_IDClient_SecretRefresh_TokenAccess_TokenClientCustomerID

我使用 Passport OAuth2 SSO 流程获取刷新令牌。

客户应该通过我们的网络应用程序登录,成功登录后我们会收到他的 access_token & refresh_token,然后我们邀请他由我们的 MCC 帐户管理,但是请求失败并且说未经授权。

What Am I doing wrong ?

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 帐户发送邀请:

  1. 您必须在您的 MCC

  2. 中创建具有相同 admin/manager 的 client_id 和 client_secret
  3. 使用具有 adwords 范围的同一用户(您的 MCC 管理员)生成 OAuth2 令牌

  4. 使用您的 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'
                    }
                }]

要在客户帐户中接受邀请:

  1. 使用客户端用户生成 OAuth2 令牌

  2. 使用客户的 adwords 帐户、活动 link 状态和 SET as operator

  3. 拨打电话
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'
                }
            }]