googleads / googleads-python-lib

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

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

Open apurvis opened 6 years ago

apurvis commented 6 years ago

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 commented 6 years ago

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 commented 3 years ago

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?