Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
265 views
in Technique[技术] by (71.8m points)

c# - Microsoft Graph OnlineMeeting API returning Status: NotFound (404) error

I am trying to create online meeting using below code and passing all the details of app registration. Still its returning 404 error.


static string[] scopes = new string[] { "https://graph.microsoft.com/.default" };
    
IConfidentialClientApplication app = ConfidentialClientApplicationBuilder.Create(LaiAppClientID).WithClientSecret(Secret).WithRedirectUri(redirectURI).Build();
    
AuthorizationCodeProvider authProvider = new AuthorizationCodeProvider(app, scopesssss);
    GraphServiceClient graphClient = new GraphServiceClient(authProvider);
    
graphClient = new GraphServiceClient("https://graph.microsoft.com/beta",
                         new DelegateAuthenticationProvider(
                              async (requestMessage) =>
                              {
                                  var token = await app.AcquireTokenForClient(scopesssss).WithAuthority(String.Format("https://login.microsoftonline.com/{0}/oauth2/v2.0/token", tenantID), true).ExecuteAsync();
                                  requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", token.AccessToken);
                               
                              }));
    
var onlineMeeting = new OnlineMeeting
                {
                    StartDateTime = DateTimeOffset.Parse("2021-07-12T21:30:34.2444915+00:00"),
                    EndDateTime = DateTimeOffset.Parse("2021-07-12T22:00:34.2464912+00:00"),
                    Subject = "My First MS Teams Meeting",
                    AudioConferencing= audioConferencing
    
                };
    
var task = Task.Run(async () =>
                {
                    return await graphClient.Me.OnlineMeetings.Request().AddAsync(onlineMeeting);
                    
                });
var d = task.Result;

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As your code shows, you use the auth code flow to get access token, then create onlineMeeting by MS Graph API. Please see my code, it works well.

string clientId = "<your-client-id>";
string clientSecret = "<your-client-secret>";
string redirectUri = "<your-redirect-url>";
string authority = "https://login.microsoftonline.com/<tenant>";
string authorizationCode = "<the authorization code>";

string[] scopes = new string[] { "https://graph.microsoft.com/.default" };

IConfidentialClientApplication app = ConfidentialClientApplicationBuilder
    .Create(clientId)
    .WithRedirectUri(redirectUri)
    .WithClientSecret(clientSecret)
    .WithAuthority(authority)
    .Build();

AuthorizationCodeProvider auth = new AuthorizationCodeProvider(app, scopes);

GraphServiceClient graphServiceClient = new GraphServiceClient(new DelegateAuthenticationProvider(async (requestMessage) => {

    // Retrieve an access token for Microsoft Graph (gets a fresh token if needed).
    var authResult = await app.AcquireTokenByAuthorizationCode(scopes, authorizationCode).ExecuteAsync();

    // Add the access token in the Authorization header of the API request.
    requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", authResult.AccessToken);
    
})
);

var onlineMeeting = new OnlineMeeting
{
    StartDateTime = DateTimeOffset.Parse("2021-07-12T21:30:34.2444915+00:00"),
    EndDateTime = DateTimeOffset.Parse("2021-07-12T22:00:34.2464912+00:00"),
    Subject = "My First MS Teams Meeting"
};

await graphServiceClient.Me.OnlineMeetings.Request().AddAsync(onlineMeeting);

Note:

authorizationCode: The auth code flow need to get this code first, then you could obtain the access token for API. See this step, you could request the url by browser and sign in with user, then it will response the code.

permission: To let it work, you need to add the permission(your application -> API permissions -> MS Graph -> Delegated permissions -> OnlineMeetings.ReadWrite) to create onlineMeeting, see here. enter image description here

Reference:

Microsoft Graph API about creating onlineMeeting by C#: link

The sample about using AuthorizationCodeProvider and more details about the code.


UPDATE:

Message: Create online meeting with application permission is only supported in beta.

The API(/v1.0) just supports delegated permission(OnlineMeetings.ReadWrite), not application permission. You could see this in the previous note.

enter image description here

Both the /beta also only supports delegated permission, see:

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...