Skip to content

NameError: name 'oauth2' is not defined when running client library setup code #349

Open

Description

@apurvis

When running the code in https://github.com/googleads/googleads-python-lib/wiki/API-access-on-behalf-of-your-clients-(web-flow)#step-2---setting-up-the-client-library I am encountering NameError: name 'oauth2' is not defined. This seems to be correct because there is no import anywhere of any oauth2 namespace.

If I change the code to

from google import oauth2
import google.oauth2.credentials
import google_auth_oauthlib.flow

flow = google_auth_oauthlib.flow.Flow.from_client_secrets_file(
    'client_secrets.json',
    scope=[oauth2.GetAPIScope('adwords')])

I get a new error: AttributeError: 'module' object has no attribute 'GetAPIScope'

Activity

  1. msaniscalchi commented on Nov 20, 2018

    @msaniscalchi
    Contributor

    Hello,

    Thanks for the report! Looks like some updates may be in order.

    So first off, the GetAPIScope function is a helper intended to get the appropriate scope for APIs supported by this library. Thus, the import you're looking for is:

    from googleads import oauth2
    

    Second, it looks like there's another issue you've not yet noticed where from_client_secrets_file is not quite correct; scope should not be a keyword argument. It should instead look like:

    flow = google_auth_oauthlib.flow.Flow.from_client_secrets_file(
        'client_secrets.json',
        [oauth2.GetAPIScope('adwords')])
    
    

    Feel free to reach out if you have any additional issues. I'll leave this open until we've updated the guide.

    Regards,
    Mark

  2. sammillendo commented on May 2, 2021

    @sammillendo

    hi @msaniscalchi I tried this but I'm getting an error that says FileNotFoundError: [Errno 2] No such file or directory:

    Should I save the json_file in my directory?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions