Reputation: 686
Edit: Ran it in python interpreter without problems, but running it with ipython always crashes.
I'm trying to get data from the Google Analytics API into an ipython notebook following the Hello Analytics tutorial with small modifications and some currently unnecessary libraries. However, every time I run that code the kernel dies without traceback / error message. Here's the whole code:
import argparse
import httplib2
from apiclient.discovery import build
from oauth2client.service_account import ServiceAccountCredentials
from oauth2client import client
from oauth2client import file
from oauth2client import tools
from httplib2 import Http
## API args
api_name = "analytics"
api_version = "v3"
scopes = ['https://www.googleapis.com/auth/analytics.readonly']
key_file_location = 'path/to/keyfile.json'
service_account_email = "[email protected]"
def get_service(api_name, api_version, scopes, key_file_location, service_account_email):
credentials = ServiceAccountCredentials.from_json_keyfile_name(key_file_location, scopes)
http_auth = credentials.authorize(Http())
service = build(api_name, api_version, http=http_auth)
return service
It's when executing the line below that the kernel dies pretty much immediately without any further information.
service = get_service(api_name, api_version, scopes, key_file_location, service_account_email)
foo = service.management().accounts().list().execute()
print(foo)
Any indication why the code doesn't work? Or are there better suited routes for accessing GA data from ipython notebooks?
Upvotes: 0
Views: 247
Reputation: 1896
Check out Google2Pandas. It an easy to use module that works perfectly in the iPython notebooks.
https://github.com/panalysis/Google2Pandas
Upvotes: 1