C# .net graph client after upgrading to v5.x

Edgar 0 Reputation points
2023-04-27T15:58:23.5433333+00:00

After upgrading graph to version v5.x the client i have dosent work, if i try to get
_graphServiceClient.Users[userEmail].JoinedTeams.GetAsync().Result;

it s never gives me a result.

this is my client

            tenantId = _configuration["xxx:tenantId"];
            clientId = _configuration["xxx:clientId"];
            clientSecret = _configuration["xxx:clientSecret"];

            // using Azure.Identity;
            var options = new TokenCredentialOptions
            {
                AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
            };

            // https://docs.microsoft.com/dotnet/api/azure.identity.clientsecretcredential
            var clientSecretCredential = new ClientSecretCredential(
                tenantId, clientId, clientSecret, options);
            _graphServiceClient = new GraphServiceClient(clientSecretCredential, scopes);
Microsoft Security Microsoft Graph
Microsoft Teams Microsoft Teams for business Other
Developer technologies C#
{count} votes

1 answer

Sort by: Most helpful
  1. CarlZhao-MSFT 46,371 Reputation points
    2023-04-28T02:39:28.87+00:00

    Hi @Edgar

    Do you want to output the result of that API call? You can refer to my sample code to print the results to the console:

    using Azure.Identity;
    using Microsoft.Graph;
    using Newtonsoft.Json;
     
      
    var scopes = new[] { "https://graph.microsoft.com/.default" };
      
    var tenantId = "{tenant id}";
     
    // Values from app registration
    var clientId = "{client id}";
    var clientSecret = "{client secret}";
     
    // using Azure.Identity;
    var options = new TokenCredentialOptions
    {
          AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
    };
     
    // https://docs.microsoft.com/dotnet/api/azure.identity.clientsecretcredential
    var clientSecretCredential = new ClientSecretCredential(
          tenantId, clientId, clientSecret, options);
       
    GraphServiceClient graphServiceClient = new GraphServiceClient(clientSecretCredential, scopes);
      
    var result = await graphServiceClient.Users["{user id}"].JoinedTeams.GetAsync();
     
    Console.WriteLine(JsonConvert.SerializeObject(result));
    

    User's image

    Hope this helps.

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.