Share via

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

Edgar 0 Reputation points
Apr 27, 2023, 3:58 PM

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 Teams
Microsoft Teams
A Microsoft customizable chat-based workspace.
10,896 questions
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
13,211 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,330 questions
{count} votes

1 answer

Sort by: Most helpful
  1. CarlZhao-MSFT 45,671 Reputation points
    Apr 28, 2023, 2:39 AM

    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.