0
編輯:冉它在python解釋器沒有問題,但運行它與ipython總是崩潰。爲什麼嘗試訪問Google AnalyticsAPI時ipython內核會死掉?
我試圖從之後的Google AnalyticsAPI中將數據從小型修改和一些當前不需要的庫中獲取到ipython筆記本中。但是,每次運行該代碼時,內核都會死亡,而不會出現回溯/錯誤消息。以下是整個代碼:
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]m.gserviceaccount.com"
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
在執行下面的行時,內核幾乎立即死亡,沒有任何進一步的信息。
service = get_service(api_name, api_version, scopes, key_file_location, service_account_email)
foo = service.management().accounts().list().execute()
print(foo)
任何指示爲什麼代碼不起作用?或者是否有更適合從ipython筆記本訪問GA數據的路由?
雖然這種鏈路可以理論上回答這個問題,[這將是優選的](// meta.stackoverflow.com/q/8259),包括在這裏的答案的主要部分,並提供鏈路以供參考。還要注意[答案几乎不超過一個鏈接可能會被刪除](http://meta.stackexchange.com/questions/225370/your-answer-is-in-an-another-castle-when-is-an-回答 - 不的回答)。 – dorukayhan