googleads / googleads-python-lib

The Python client library for Google's Ads APIs
Apache License 2.0
681 stars 974 forks source link

How to check if the service account is connected/invited to the someone else Google Ads? #541

Closed dendihandian closed 6 months ago

dendihandian commented 6 months ago

I have this code:

from googleads import ad_manager
from googleads import oauth2

oauth2_client           = oauth2.GoogleServiceAccountClient('./path-to-the-service-account-file.json', oauth2.GetAPIScope('ad_manager'))
ad_manager_client   = ad_manager.AdManagerClient(oauth2_client=oauth2_client, application_name='my_application_name')

when I list the networks with this, it returns empty list:

    networks = ad_manager_client.GetService('NetworkService').getAllNetworks()
    for network in networks:
        print('Network with network code "%s" and display name "%s" was found.' % (network['networkCode'], network['displayName']))

I'm pretty sure the my service account email is already connected/invited to the google ads manager. How to find out if it's connected in programmatically?

christopherseeley commented 6 months ago

The method you're calling is the correct way to determine access programmatically. Note that service accounts must be added directly in the network settings page, not invited: https://support.google.com/admanager/answer/6078734?

You can check the network's users in the UI and filter on "Service account" to determine if the service account was directly added.