How can I use oauth2 pipeline to link a account to a MMC in python

104 views
Skip to first unread message

Eduardo Cesar

unread,
Aug 24, 2017, 12:52:02 PM8/24/17
to AdWords API Forum
I'm using the outh2 to get the customer refresh token, access token and etc. However, when I get the customer informations using this method, I can't see the customer account in my google account using the browser. 
Is it possible link the customer account in the authentication proccess to my MMC account? If it is possible, can I use my MMC refresh token to access de Google Adwords API instead of the customer refresh token (passing the using the customer id only)?

Shwetha Vastrad (AdWords API Team)

unread,
Aug 24, 2017, 4:02:35 PM8/24/17
to AdWords API Forum
Hi Eduardo, 

To link an existing AdWords client account to your MCC account, you should follow these steps:
  1. The MCC account must extend an invitation to the client account.
  2. The client account must accept the invitation.
You should ensure that you use your MCC's OAuth2 credentials for the first step and the client account's OAuth2 credentials for the second step. Once your AdWords manager account is linked to the client account, you should be able to use your manager account's refresh token to target the client account as well. 

Regards,
Shwetha, AdWords API Team.

Eduardo Cesar

unread,
Aug 24, 2017, 4:13:52 PM8/24/17
to AdWords API Forum
Thanks, Shwetha.

Is there in google developer area any tutorial in Python?

Shwetha Vastrad (AdWords API Team)

unread,
Aug 25, 2017, 1:59:25 PM8/25/17
to AdWords API Forum
Hi, 

While there isn't a consolidated tutorial in Python, you can follow the getting started guide in the library's repository which shows how to set up the AdWords API Python library. The wiki page lists some useful resources as well. 

Eduardo Cesar

unread,
Aug 25, 2017, 8:29:48 PM8/25/17
to AdWords API Forum
Thanks for the links,

I create a helper function as you can see below that invites a client to link the account to MMC. However, i'm getting 'ManagedCustomerServiceError.NOT_AUTHORIZED'. If I remove the SetCLientCustomerId, I receive 'AuthenticationError.CLIENT_CUSTOMER_ID_IS_REQUIRED'.
The variables below are:
   - CIENT_ID: Application Client Id;
   - CLIENT_SECRET: Application Client Secrete;
   - refresh_token: Client Customer refresh token got in oauth steps;
   - DEVELOPER_TOKEN: Application Developer token;
   - customer_id: Client customer id (correctly got in oath2 steps + api method);
   - MANAGER_ID: MCC Id;

def invite_account(customer_id, refresh_token):
oauth2_client = oauth2.GoogleRefreshTokenClient(CLIENT_ID, CLIENT_SECRET, refresh_token)
adwords_client = adwords.AdWordsClient(DEVELOPER_TOKEN, oauth2_client)
adwords_client.SetClientCustomerId(customer_id)
managed_customer_service = adwords_client.GetService('ManagedCustomerService',
version='v201709')

operation = {
'operator': 'ADD',
'operand': {
'managerCustomerId': MANAGER_ID,
'clientCustomerId': customer_id,
'linkStatus': 'PENDING',
'pendingDescriptiveName': 'Pareto Quantic is inviting yout account',
'isHidden': False
}
}

Shwetha Vastrad (AdWords API Team)

unread,
Aug 28, 2017, 12:28:29 PM8/28/17
to AdWords API Forum
Hi Eduardo,

While extending the invitation from the Manager account, you need to set the clientCustomerId to the Manager's account ID and use the Manager's OAuth2 credentials. This is the reason you receive ManagedCustomerServiceError.NOT_AUTHORIZED. The Client customer ID is required for all cases except for when using CustomerService.getCustomers() and ReportDefinitionService. Could you retry the request by making these changes and let me know if it works? 

Eduardo Cesar

unread,
Aug 28, 2017, 1:25:16 PM8/28/17
to AdWords API Forum
Hi Shwetha,

When I use the Manager account in authentication, I get this error message "oauth2client.client.HttpAccessTokenRefreshError: unauthorized_client".

Regads,

Eduardo Cesar

Shwetha Vastrad (AdWords API Team)

unread,
Aug 28, 2017, 4:55:32 PM8/28/17
to AdWords API Forum
Hi Eduardo, 

Could you try generating a new refresh token for your Manager account and retry the request? Could you also provide the following details using the Reply privately to author option? 
  • SOAP request and response for this mutateLink operation. 
  • The email address used to generate the OAuth2 credentials used for this request. 
Once I have these details, I'll be able to further investigate. 

Thanks,
Shwetha, AdWords API Team.

Eduardo Cesar

unread,
Aug 30, 2017, 7:48:48 AM8/30/17
to AdWords API Forum
It works! The mcc refresh token now is correct and I can invite clients in API.

Thanks!

Regards,

Eduardo Cesar 
Reply all
Reply to author
Forward
0 new messages