2015-09-01 50 views
0

我剛剛安裝了Anaconda(默認情況下爲Python 3),因爲我需要熊貓/訪問Google Analytics。下面是有關訪問GA通過Python的&大熊貓的一些信息:http://pandas.pydata.org/pandas-docs/stable/remote_data.html#remote-data-gaGoogle API client_secrets錯誤

類似的問題在這裏Google API client secrets error (Python)問,但答案似乎在我的具體情況沒有幫助。也就是說,我的錯誤是不同的;我已將client_secrets.json文件放入相應的目錄中;該文件不是空的,並且與開發者控制檯中顯示的內容完全相同。

下面是代碼和錯誤:

  • 除了蟒蛇,我還安裝了Google API libraryGFlags
  • 看來GFlags在是:有關安裝

    import numpy as np 
    import pandas as pd 
    import pandas.io.ga as ga 
    from pandas import Series, DataFrame 
    
    df = ga.read_ga(metrics='sessions', dimensions='date', start_date='2015-07-01') 
    
    An exception has occurred, use %tb to see the full traceback. 
    
    SystemExit: 
    WARNING: Please configure OAuth 2.0 
    
    You need to populate the client_secrets.json file found at: 
    
    /Users/usernamehere/anaconda/envs/py2/lib/python2.7/site-packages/pandas/io/client_secrets.json 
    
    with information from the APIs Console <https://code.google.com/apis/console>. 
    

    一些額外的細節與Python 3不兼容,所以我創建了一個新環境,使用the conda create method

  • Google帳戶用於訪問Google Developer Console已啓用雙因素驗證

回答

0

看起來像谷歌開發者控制檯用於提供默認的URI重定向,但現在不再。

當設置客戶端機密,確保以下內容添加到「授權的重新導向的URI」:

​​

這必須是準確的 - 甚至是缺失的/會導致錯誤。檢查此的一種方法是確保client_secrets.json文件具有以下行:

"redirect_uris":["http://localhost:8080/"]