Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
apurvis opened this issue Nov 20, 2018 · 2 comments
Labels

Comments

@apurvis
Copy link

apurvis commented Nov 20, 2018

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'

@msaniscalchi
Copy link
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

@sammillendo
Copy link

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
Labels
Projects
None yet
Development

No branches or pull requests

3 participants