Teams團隊的成員列表API的已知問題

如果大家經常使用Graph API來對Teams進行操作管理的話,有時候會遇到一些奇怪的問題,我前兩天還在Stack Overflow上回答了一個用戶的問題,這個問題我自己也遇到過。所以我想用這篇文章來分享一下,萬一以後大家遇到類似的問題,就有所防備。

這個問題實際上是一個已知問題,官方的解釋在這裏

We recommend that when you add an owner, you also add that user as a member. If a team has an owner who is not also a member, ownership and membership changes might not show up immediately in Microsoft Teams. In addition, different apps and APIs will handle that differently. For example, Microsoft Teams will show teams that the user is either a member or an owner of, while the Microsoft Teams PowerShell cmdlets and the /me/joinedTeams API will only show teams the user is a member of. To avoid confusion, add all owners to the members list as well.

講的是說,如果我們需要給一個團隊(team)增加一個owner,那你不單單需要把這個用戶加入到owner列表,還需要把他加入到member成員列表。如果你直加了一個列表,那就可能有問題。不同的程序對於這個用戶的判斷會不一致。

比如:你把用戶A加入到一個團隊(team)的owner列表,但是沒有把這個用戶加入到成員member列表。那麼,你使用powershell的cmdlet,和/me/joinedTeams這個API就會認爲這個用戶A還不在這個團隊裏。

所以,爲了防止這類事情的發生,建議的做法是:如果你要把用戶加入到owner列表,那同時你也應該把這個用戶加入到成員列表。

另外,還有一個已知問題,我之前也遇到了。官方是這麼說的:

Known issue: when DELETE /groups/{id}/owners is called, the user is also removed from the /groups/{id}/members list. To work around this, we recommend that you remove the user from both owners and members, then wait 10 seconds, then add them back to members.

意思是:當你想把一個用戶移出owner列表,也就是說這個用戶不在是這個團隊的擁有者。我們通常會使用這個API

DELETE /groups/{id}/owners/{userId}/$ref

但是詭異的地方是,如果你這麼做了之後,這個用戶會自動從這個團隊的member成員列表裏移出,也就是說,他連普通的成員身份都沒有了。也就是說相當於自動幫你調用了DELETE /groups/{id}/members/{userId}/$ref接口。

目前官方建議的workaround是當你調用DELETE /groups/{id}/owners/{userId}/$ref把這個用戶移出owner擁有者列表後,等10秒鐘(注意,官方建議要等10秒鐘,不能立刻),然後再調用下面這個接口來吧用戶加回到member成員列表。

POST /groups/{id}/members/$ref

希望這兩個已知問題能儘快得到產品團隊的解決,也希望這篇文章能在大家遇到類似的問題時,對大家有幫助。

另外,強烈推薦微軟牛人Ares陳老師的Teams開發系列視頻講座:Microsoft Teams開發入門和實踐 https://aka.ms/teamsdev163study ,從入門到精通Teams開發!本篇博客裏提到的GraphAPI在章節4中有詳細解說。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章