在创建包含节点的Confluence插件时,我想要检索用户的帐户信息。
如何获取当前正在运行的用户的ID和名称?如果我只有用户的ID,我如何获取他们的信息(即全名,用户名,profilepic等)?
我从Java的角度找到了一些如何使用它的资源......
(2)https://docs.atlassian.com/confluence/latest/com/atlassian/confluence/user/UserAccessor.html
他们的文档甚至还有如何从前端获取id和用户名: https://developer.atlassian.com/static/connect/docs/latest/javascript/module-User.html
虽然,我没有看到节点的任何内容。
答案 0 :(得分:1)
在Atlassian Connect插件中,您可以通过获取发送到附加组件的user_id
请求参数来检索用户名。
例如,这是Gister Macro for Confluence Cloud上this page的{{3}}来电:
https://davidsimpson.me/labs/gister-for-confluence-cloud/gister.html?gistUrl=https%3A%2F%2Fgist.github.com%2Fdvdsmpsn%2Fa7910d336c5864201837
tz=Europe%2FLondon
loc=en-GB
user_id=dvdsmpsn
user_key=ff8080814b99b7f1014b99b80fda0001
xdm_e=https%3A%2F%2Fdvdsmpsn.atlassian.net
xdm_c=channel-gister-macro2158065749017340142
cp=%2Fwiki
lic=none
cv=1.1.44
如果您知道用户user_id
(在这种情况下为dvdsmpsn
),您可以发送REST呼叫,例如
https://dvdsmpsn.atlassian.net/wiki/rest/prototype/1/search/user.json?query=dvdsmpsn
这会给出回复:
{
"totalSize":1,
"result":[
{
"id":"491522",
"type":"user",
"title":"David Simpson [Administrator]",
"wikiLink":"[~dvdsmpsn]",
"createdDate":{
"friendly":"Feb 17, 2015",
"date":"2015-02-17T22:57:26+0000"
},
"creator":{
"links":[
{
"href":"https://dvdsmpsn.atlassian.net/wiki/rest/prototype/1/user/non-system/dvdsmpsn",
"rel":"self"
}
],
"avatarUrl":"/wiki/download/attachments/491522/user-avatar?version=1&modificationDate=1425823096051&api=v2",
"displayableEmail":"david@davidsimpson.me",
"anonymous":false,
"name":"dvdsmpsn",
"displayName":"David Simpson [Administrator]"
},
"lastModifier":{
"links":[
{
"href":"https://dvdsmpsn.atlassian.net/wiki/rest/prototype/1/user/non-system/dvdsmpsn",
"rel":"self"
}
],
"avatarUrl":"/wiki/download/attachments/491522/user-avatar?version=1&modificationDate=1425823096051&api=v2",
"displayableEmail":"david@davidsimpson.me",
"anonymous":false,
"name":"dvdsmpsn",
"displayName":"David Simpson [Administrator]"
},
"username":"dvdsmpsn",
"userKey":"ff8080814b99b7f1014b99b80fda0001",
"thumbnailLink":{
"href":"https://dvdsmpsn.atlassian.net/wiki/download/attachments/491522/user-avatar?version=1&modificationDate=1425823096051&api=v2",
"type":"image/png",
"rel":"thumbnail"
},
"link":[
{
"href":"https://dvdsmpsn.atlassian.net/wiki/display/~dvdsmpsn",
"type":"text/html",
"rel":"alternate"
},
{
"href":"https://dvdsmpsn.atlassian.net/wiki/spaces/flyingpdf/pdfpageexport.action?pageId=491522",
"type":"application/pdf",
"rel":"alternate"
},
{
"href":"https://dvdsmpsn.atlassian.net/wiki/rest/prototype/1/content/491522",
"rel":"self"
}
]
}
],
"group":[
]
}
好的,这是使用"已弃用"原型REST API,但是由于缺少替代品,你必须只使用可用的东西。