Google API client secrets error (Python)

試著忘記壹切 提交于 2019-12-06 03:00:31

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.

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.

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)

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.

yacine

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.

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