2015-07-06 24 views
2

我正在使用Google AnalyticsAPI和SDK。登錄用戶後,我想顯示他的名字。相反,當我打電話給用戶的廣告帳戶時,API只返回沒有顯示名稱的電子郵件。我正在使用https://www.googleapis.com/auth/analytics.edit範圍。如何從Google Analytics API獲取用戶名?

這裏就是我得到:

object(Google_Service_Analytics_Accounts)[86] 
    protected 'collection_key' => string 'items' (length=5) 
    protected 'internal_gapi_mappings' => ... 
    protected 'itemsType' => string 'Google_Service_Analytics_Account' (length=32) 
    protected 'itemsDataType' => string 'array' (length=5) 
    public 'itemsPerPage' => int 1000 
    public 'kind' => string 'analytics#accounts' (length=18) 
    public 'nextLink' => null 
    public 'previousLink' => null 
    public 'startIndex' => int 1 
    public 'totalResults' => int 2 
    public 'username' => string '[email protected]' (length=12) 
    protected 'modelData' => ... 
    protected 'processed' => ... 

我怎樣才能獲得用戶名?我需要使用其他Google API嗎?

+0

認爲您可以做的最好的事情是將用戶配置範圍添加到您的任務中,然後請求來自Google+ api的信息Google分析API無法訪問任何用戶名。 – DaImTo

+0

是的,我認爲是。問題是應用程序需要啓用Google Plus API。如果這是唯一的方法,我會做到這一點。我會等待更多的答案。請添加您的評論作爲答案,所以也許我們可以在以後做出最好的答案:) –

回答

3

不幸的是,Google AnalyticsAPI無法訪問電子郵件以外的用戶信息。

即使你檢查Account users list它不返回用戶名:

"userRef": { 
    "kind": "analytics#userRef", 
    "id": "117200475532672775346", 
    "email": "[email protected]" 
    }, 

的辦法是添加profile範圍是了Google+ API的一部分。您將可以使用people.get。只需添加me作爲用戶ID,它將返回檔案信息爲當前在認證的人:

"objectType": "person", 
"id": "117200475532672775346", 
"displayName": "Linda Lawton", 
"name": { 
    "familyName": "Lawton", 
    "givenName": "Linda" 
}, 

或者我想從Analytics帳戶的要求,你可以採取的ID。他們似乎是相同的ID。

相關問題