ManagedCustomerServiceError.NOT_AUTHORIZED

554 views
Skip to first unread message

Патапоша Потапенко

unread,
Feb 23, 2017, 12:21:26 PM2/23/17
to AdWords API Forum

Hi!
I'm trying to invite customers to my manage account using ManagedCustomerService and accept that invitation on behalf of the customer using this https://github.com/googleads/googleads-python-lib/wiki/API-access-on-behalf-of-your-clients-(web-flow) example.

Here is my code:

`flow = client.OAuth2WebServerFlow(
client_id=g_appID,
client_secret=g_secret,
scope=oauth2.GetAPIScope('adwords'),
user_agent='Pata',
redirect_uri='http://127.0.0.1:5000/get_Gtoken')
code = request.args['code']
credentials = flow.step2_exchange(code)
print credentials.to_json()

oauth2_client = oauth2.GoogleRefreshTokenClient(
    credentials.client_id, credentials.client_secret, credentials.refresh_token)

# getting customer_id
adwords_client = adwords.AdWordsClient(g_devToken, oauth2_client)
customer = adwords_client.GetService('CustomerService', version='v201609').getCustomers()
customer_id = customer[0]['customerId']
print customer_id

# inviting customer with my manage acc
adwords_manager = adwords.AdWordsClient.LoadFromStorage('googleads.yaml')
managed_customer_service = adwords_manager.GetService('ManagedCustomerService', version='v201609')
operations = [{
    'operator': 'ADD',
    'operand': {
        'managerCustomerId': adwords_manager.client_customer_id,
        'clientCustomerId': customer_id,
        'linkStatus': 'PENDING',
    }
}]
managed_customer_service.mutateLink(operations)

# accepting invitation on behalf of the customer
adwords_client2 = adwords.AdWordsClient(g_devToken, oauth2_client, client_customer_id=customer_id)

managed_customer_service2 = adwords_client2.GetService('ManagedCustomerService', version='v201609')
selector = {
    'managerCustomerIds': adwords_manager.client_customer_id,
    'clientCustomerIds': adwords_client2.client_customer_id
}
page = managed_customer_service2.getPendingInvitations(selector)
print page`

I'm getting '[ManagedCustomerServiceError.NOT_AUTHORIZED @ ]' error after
page = managed_customer_service2.getPendingInvitations(selector)
That seems strange for me, because if I replace last step to this:
campaign_service = adwords_client2.GetService('CampaignService',version='v201609')

selector = {
    'fields': ['Id', 'Name', 'Status'],
    'paging': {
        'startIndex': str(0),
        'numberResults': str(100)
    }
}

page = campaign_service.get(selector)
for campaign in page['entries']:
    print campaign['id']`

I'm successfully getting all customer's campaigns.
What am I doing wrong?
Is it forbidden to automatically accept invitation?
P.S. That invitation is also successfully displayed in both of Adwords cabinets.

Shwetha Vastrad (AdWords API Team)

unread,
Feb 23, 2017, 12:46:59 PM2/23/17
to AdWords API Forum
Hi,

Could you check the access level of the login associated with the credentials used to accept the invitation? The access level of the login email applies to API requests as well. Only users with Administrative access can accept and reject manager account link requests. If these credentials were created by a user with Standard access, you'll encounter the ManagedCustomerServiceError.NOT_AUTHORIZED error. Users with Standard access can retrieve and edit any part of an account and its campaigns. This is why you can retrieve the customer's campaigns, but cannot accept the invitation from the Manager account. 

This guide provides more information about access level in AdWords. Please use an Administrative login to generate your OAuth2 credentials for the client account and retry the request to accept the invitation. 

Regards,
Shwetha, AdWords API Team.

Патапоша Потапенко

unread,
Feb 23, 2017, 1:14:35 PM2/23/17
to AdWords API Forum

The access level of customer acc is Administrative. But it does not connected to any manage acc yet.

Shwetha Vastrad (AdWords API Team)

unread,
Feb 23, 2017, 2:41:40 PM2/23/17
to AdWords API Forum
Hi,

Could you enable logging and provide the SOAP request and response logs for the ManagedCustomerService.getPendingInvitations() request? Please use Reply privately to author when responding. 

Thanks,
Shwetha, AdWords API Team.
Reply all
Reply to author
Forward
0 new messages