Google API client secrets error (Python)

点点圈 提交于 2020-01-23 11:42:46

问题


I want to retrieve data from Google analytics. I have created a service account in the console and I am using Google's Python (hello_analytics_api_v3.py) code to access the data.

I have copied the client_secrets.json into my folder but get this error:

*SystemExit: 
WARNING: Please configure OAuth 2.0
To make this sample run you will need to populate the client_secrets.json file
found at:*

What should I do? I am using Python 2.7.


回答1:


Ensure the terminal is pointing to the same path directory as your client_secrets.json file.

i.e. type pwd in the console you're using to call the script and the output should match the directory of where client_secrets.json is stored.




回答2:


I was having this exact issue and deleted the credentials to my project and creating new ones using the 'OAuth client ID' option. Follow step one of this page closley https://developers.google.com/analytics/devguides/config/mgmt/v3/quickstart/installed-py

I also found a syntax error in the sample code provided by google The Lines:

print 'View (Profile): %s' % results.get('profileInfo').get('profileName')
print 'Total Sessions: %s' % results.get('rows')[0][0]

Should read:

print ('View (Profile): %s' % (results.get('profileInfo').get('profileName')))
print ('Total Sessions: %s' % (results.get('rows')[0][0]))

At least this solved it for me. Also, make sure the client_secrets.json is in the same directory as your python script.




回答3:


In the sample code at https://developers.google.com/youtube/v3/guides/uploading_a_video the call to flow_from_clientsecrets() passes CLIENT_SECRETS_FILE as a relative path.

To fix it, force the CLIENT_SECRETS_FILE argument to be an absolute path:

def get_authenticated_service(args):
  flow = flow_from_clientsecrets(
    os.path.abspath(os.path.join( 
      os.path.dirname(__file__),CLIENT_SECRETS_FILE)),
    scope=YOUTUBE_UPLOAD_SCOPE,
    message=MISSING_CLIENT_SECRETS_MESSAGE)



回答4:


I received this error because I still had the square brackets inside the client_id and client_secret. It should just be the string with no brackets.




回答5:


If you are using Windows system, follow this steps:

  1. Put your file (client_secrets.json) in the directory (C:) or (D:).
  2. In your Python file define your variable like this: CLIENT_SECRETS_FILE = "\client_secrets.json". Python will search the json file in the root C: or D: and will find it.

I had same problem with Google API for youtube and I solved it like that.



来源:https://stackoverflow.com/questions/13858927/google-api-client-secrets-error-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!