将Adwords帐户链接到MCC帐户,Adwords API,NodeJ

时间:2018-11-05 19:29:14

标签: node.js google-adwords adwords-api-v201802

我正在尝试使用Node Adwords NPM软件包将Adwords帐户链接到MCC帐户

  1. 我对这两个帐户具有 MANAGER / Admin Access (管理员/管理员访问权限)(不是同一封电子邮件)
  2. 我在Google控制台开发人员上创建了一个项目/应用程序来获取
    使用MCC电子邮件用户 Client_ID Client_Secret
  3. 我使用上述凭据恢复了访问令牌/刷新令牌
  4. 现在使用具有标准访问权限, Client_ID Client_Secret Refresh_Token Access_Token 和< strong> ClientCustomerID

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

客户应通过我们的Web应用程序登录,一旦成功登录,我们将收到他的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)
    })

1 个答案:

答案 0 :(得分:0)

要从“我的客户中心”发送邀请到adwords帐户:

  1. 您必须在MCC中使用相同的管理员/经理创建一个client_id和client_secret

  2. 使用adwords范围(您的MCC的经理)与具有同一用户的OAuth2令牌生成

  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 = 'MCCAccountCustomerID';
 customerService = adwordsUser.getService('ManagedCustomerService', null);
 operations: [{
                    operator: 'ADD',
                    operand: {
                        managerCustomerId: 'MCCAccountCustomerID',
                        clientCustomerId: 'AdwordsAccountID', // Account to invite
                        linkStatus: 'PENDING'
                    }
                }]

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

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

  2. 使用客户的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'
                }
            }]