4

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.

bossylobster
  • 9,993
  • 1
  • 42
  • 61
Dirk N
  • 717
  • 3
  • 9
  • 23

5 Answers5

12

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.

zsoobhan
  • 1,484
  • 15
  • 18
3

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.

2

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)
Justin M. Keyes
  • 6,679
  • 3
  • 33
  • 60
1

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.

Chris
  • 676
  • 5
  • 20
0

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.

phss
  • 1,012
  • 10
  • 22
yacine
  • 147
  • 1
  • 6