gpt4 book ai didi

google-analytics - 如何从Google Analytics(分析)API获取用户名?

转载 作者:行者123 更新时间:2023-12-03 15:48:25 26 4
gpt4 key购买 nike

我正在使用Google Analytics(分析)API和SDK。登录用户后,我想显示他的名字。相反,当我调用用户的广告帐户时,API仅返回没有显示名称的电子邮件。我正在使用https://www.googleapis.com/auth/analytics.edit范围。

这就是我得到的:

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 'me@gmail.com' (length=12)
protected 'modelData' => ...
protected 'processed' => ...


如何获得用户名?我需要使用其他Google API吗?

最佳答案

不幸的是,Google Analytics(分析)API无法访问电子邮件以外的有关用户的信息。

即使您选中Account users list,它也不会返回用户名:

 "userRef": {
"kind": "analytics#userRef",
"id": "117200475532672775346",
"email": "xxx@gmail.com"
},


一种选择是添加 profile范围,该范围是Google+ API的一部分。然后,您将可以使用 people.get。只需添加 me作为用户ID,它将返回当前已通过身份验证的人的个人资料信息:

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


或者我想您可以从Google Analytics(分析)帐户请求中获取ID。它们似乎是相同的ID。

关于google-analytics - 如何从Google Analytics(分析)API获取用户名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31242509/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com