googleads-python-lib
googleads-python-lib copied to clipboard
NameError: name 'oauth2' is not defined when running client library setup code
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'
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
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?