2014-02-06 85 views
1

我正在將this tutorial應用到symfony 2.4中,我完成了config.yml和所有設置中的設置,我設法訪問了admin/google/analytics頁面,但問題是當我嘗試使用我在config.yml文件中創建的參數進行身份驗證,它正在搜索範圍,這裏是參數。沒有指定範圍 - Google_Auth_Exception

happy_r_google_analytics: 
    host: www.example.com 
    profile_id: MyProfileId 
    tracker_id: UA-TRACKER-ID 
    token_file_path: %kernel.root_dir%/var/storage 
happy_r_google_api: 
    application_name: Project Default Service Account 
    oauth2_client_id: OAuthClientID 
    oauth2_client_secret: OAuthClientSecret 
    oauth2_redirect_uri: http://www.example.com/app_local.php/admin/google/analytics/oauth2callback 
    developer_key: DevelopperKey 
    site_name: http://www.example.com 

我認爲這裏沒有問題,我沒有想法,我可以設置範圍,所以,谷歌API客戶端可以將其設置爲https://www.googleapis.com/auth/analytics.readonly

回答

4

您需要定義範圍。如果您使用Google身份驗證,請檢查Authorization scopes

你必須做一些事情,如:

$googleClient = new \Google_Client(); 
    $googleClient->setScopes(array(
     'https://www.googleapis.com/auth/plus.me', 
     'https://www.googleapis.com/auth/userinfo.email', 
     'https://www.googleapis.com/auth/userinfo.profile', 
    )); 
+0

我想實現一個服務器到服務器的OAuth2我覺得範圍必須不從。我只會找到關於如何獲得分析數據的其他教程,您的答案對於實現Web應用程序的人員,服務器到服務器的服務帳戶是正確的,但在symfony中很難實現。 – Cedric

+0

也許你最好試着用控制器或服務手動實現它,不要使用供應商捆綁包? –

+1

經過長時間的研究後,我遇到了Google Analytics的GAPI,我已經將它創建爲我的包的一個對象,並在我的控制器中調用它,所以我想我現在將離開供應商包。乾杯! – Cedric