尝试显示一些公共GitLab用户的自定义属性(主要是location字段)。但这不起作用
我正在使用python gitlab库来获取列表。我可以打印用户名,ID和URL。 现在,我想访问自定义属性,例如位置,但是它对我不起作用! 我正在尝试从浏览器中进行以下操作,使其无法正常工作(例如:username = gitlab)
https://gitlab.com/api/v4/users?username=gitlab&private_token=mytoken
# this brings the users list
import gitlab
gl = gitlab.Gitlab('http://gitlab.com', private_token='mytoken')
users = gl.users.list()
for u in users:
print (u.name)
print (u.id)
print (u.web_url)
答案 0 :(得分:0)
请注意以下摘录自官方API文档:
对自定义属性的每个API调用都必须经过管理员身份验证。自定义属性当前可用于用户,组和项目,在本文档中将其称为“资源”。
您用来进行身份验证的帐户似乎必须具有查询的GitLab实例的管理权限。检查您的特定帐户和GitLab实例是否属于这种情况。
您可以在custom attributes section.中找到有关自定义用户属性的python-gitlab API文档 另外,还有this feature的官方API文档。
在您的示例中,有效的呼叫应如下所示:
import gitlab
gl = gitlab.Gitlab('http://gitlab.com', private_token='mytoken')
users = gl.users.list()
for user in users:
attrs = user.customattributes.get('location')