Getting Teams Calls returns Application not regist

2020-06-28 15:53发布

I'm struggling with Microsft Graph. I want to fetch Teams Calls from the graph API to throw them against our ticket software. Sounds easy at first. And I think it is but I don't get why it won't work.

Edit: Just a heads up. I ended up using the Microsoft Graph subscription model.

To be clear, I don't want to create a teams app, I just want to fetch Teams Calls/Meetings.

This is my code (removed ID's for obvious reasons):

class Program
{
    // (Company IDs)
    static string tenantId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
    static string servicePrincipal = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
    static string servicePrincipalKey = "keyyyyy";

    // Admin consent if not already applied
    // https://login.microsoftonline.com/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/adminconsent?client_id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx&state=randomState
    // In my case admin consent was given via azure portal for the following permissions:
    // Yes, it's too much. But I'm desperate...
    /* Microsoft Graph (10)
        CallRecords.Read.All
        Calls.AccessMedia.All
        ChannelMessage.Read.All
        Chat.Read.All
        IdentityProvider.Read.All
        OnlineMeetings.Read.All
        TeamsActivity.Read.All
        TeamsApp.Read.All
        User.Read.All 
    */

    static string[] scopes = {
        "https://graph.microsoft.com/.default",
        //"https://graph.microsoft.com/CallRecords.Read.All" // doesn't work
        //"https://graph.microsoft.com/TeamsApp.Read.All" // doesn't work
        //"https://graph.microsoft.com/Chat.ReadWrite.All" // doesn't work
    };
    static async Task Main(string[] args)
    {

        var authority = $"https://login.microsoftonline.com/" + "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + "/v2.0";

        var clientConf = ConfidentialClientApplicationBuilder
            .Create(servicePrincipal)
            .WithAuthority(authority, true)
            .WithClientSecret(servicePrincipalKey)
            .Build();

        GraphServiceClient graphClient = new GraphServiceClient(new DelegateAuthenticationProvider(async(requestMessage) =>
        {
            var authResult = await clientConf
                .AcquireTokenForClient(scopes)
                .ExecuteAsync();
            requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", authResult.AccessToken);
        }));

        //_ = graphClient.Teams.Request().GetAsync(); // Debug test

        // Trying to fetch all calls or meetings
        var onlineMeetings = await graphClient
            .Communications.Calls.Request().GetAsync(); // Doesn't work
        //.Users.Request().GetAsync(); // This works!
        //.Communications.OnlineMeetings.Request().GetAsync(); // Doesn't work

        Console.WriteLine(onlineMeetings);
        // If requesting users, this works without issues 
        /*
        var count = 0;
        foreach (var user in onlineMeetings) {
            Console.WriteLine(count);
            Console.WriteLine(user.UserPrincipalName);
            count++;
        }
        */

    }
}

When I run this mess I get the follwing error:

"Microsoft.Graph.ServiceException in System.Private.CoreLib.dll"
Code: UnknownError
{
  "errorCode":"7503",
   "message":"`**Application is not registered in our store.**`",
   "instanceAnnotations":[]
}

Does anyone have an idea on what I'm doing wrong here?

Stacktrace

ClientRequestId: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
    at Microsoft.Graph.HttpProvider.<SendAsync>d__18.MoveNext()
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
    at Microsoft.Graph.BaseRequest.<SendRequestAsync>d__35.MoveNext()
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
    at Microsoft.Graph.BaseRequest.<SendAsync>d__31`1.MoveNext()
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
    at Microsoft.Graph.CloudCommunicationsCallsCollectionRequest.<GetAsync>d__4.MoveNext()
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
    at Teams_Graph.Program.<Main>d__4.MoveNext() in c:\Users\<user.name>\Documents\Development\C#\Teams-Graph\Program.cs: Line50

1条回答
疯言疯语
2楼-- · 2020-06-28 16:47

There isn't an API for listing all Calls or Meetings in an organization. You need to specify the id of the Call/Meeting you want:

var Calls = await graphClient
    .Communications
    .Calls["{call id}"]
    .Request()
    .GetAsync();

var onelineMeeting = await graphClient
    .Communications
    .OnlineMeetings["{meeting id"]
    .Request()
    .GetAsync();
查看更多
登录 后发表回答