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 afterpage = 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.