简体   繁体   中英

Graph api get members of channel not able get the userId

the response of the get members of the channels has userid, when we debugg it we can find it in the response

but when we try to

 var response = await graphClient.Teams[teamid].Channels[channeId].Members
                        .Request()
                        .GetAsync();
        foreach (var res in response)
        {
            var member = new Members();
            member.UserId = res.Id;      //this id is not user id 
            member.FullName = res.DisplayName;
            members.Add(member);
        }

The response has userId, not able to get the userID, how do we retrive userId

I assume your debug code is accessing the beta api, while the your code snippet is using the v1.0 api.

GET https://graph.microsoft.com/beta/Teams/02bd9fd6-8f93-4758-83-1fb73740a315/channels/19:09fc54a3141a45d0bc769cf506d279@thread.skype/members

{
    "@odata.context": "https://graph.microsoft.com/beta/$metadata#teams('09fd6-8f93-4758-87c3-1fb73740a315')/channels('19%3A09fc54a3141a45d0b69cf506d2e079%40thread.skype')/members",
    "@odata.count": 19,
    "value": [
        {
            "@odata.type": "#microsoft.graph.aadUserConversationMember",
            "id": "MCMjMiMjZGNkMjE5ZGQtYmM2OC00YjliLWJmMGItNGEzM2E3OTZiZTM1IyMxOTowOWZjNTRhMzE0MWE0NWQwYmM3NjljZjUwNmQyZTA3OUB0aHJlYWQuc2t5cGUjIzA3NGU1NmVhLTBiNTAtNDQ2MS04OWU1LWM2N2FlMTRhMmMwYg==",
            "roles": [],
            "displayName": "Lee Gu",
            "visibleHistoryStartDateTime": "0001-01-01T00:00:00Z",
            "userId": "074e56ea-0b50-4461-89e5-ae14a2c0b",
            "email": "LeeG@M365x2143.onmicrosoft.com",
            "te
...

versus the 1.0 api:

GET https://graph.microsoft.com/v1.0/Teams/02bd9fd6-8f93-4758-87c3-1fb73740a315/channels/19:09fc54a3141a45d0bc769cf506d2e079@thread.skype/members

{
    "error": {
        "code": "Forbidden",
        "message": "Caller does not have the required permissions for accessing this API. AllowedPermissions:'ChannelMember.Read.All,ChannelMember.ReadWrite.All'",
        "innerError": {
            "date": "2022-02-07T23:54:32",
            "request-id": "d82250a3-9637-4626-8afd-499ea3fd519e",
            "client-request-id": "d82250a3-9637-4626-8afd-499ea3fd519e"
        }
    }
}

the v1.0 api appears to have more stringent permission requirements.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM