Microsoft Graph OnlineMeeting API返回状态:未找到(404)错误 [英] Microsoft Graph OnlineMeeting API returning Status: NotFound (404) error
问题描述
我正在尝试使用以下代码创建在线会议,并传递应用注册的所有详细信息. 仍然是返回的404错误.
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;
推荐答案
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);
注意:
authorizationCode :身份验证代码流需要首先获取此代码,然后才能获取API的访问令牌.参见
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.
权限:要使其正常工作,您需要添加权限(您的应用程序-> API权限-> MS Graph-> 委派的权限-> ; OnlineMeetings.ReadWrite)创建onlineMeeting,请参见
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.
参考:
有关通过C#创建onlineMeeting的Microsoft Graph API:
Microsoft Graph API about creating onlineMeeting by C#: link
有关使用AuthorizationCodeProvider
和更多
The sample about using AuthorizationCodeProvider
and more details about the code.
更新:
消息:仅具有应用程序许可的创建在线会议 在Beta中受支持.
Message: Create online meeting with application permission is only supported in beta.
API(/v1.0)仅支持委派权限(OnlineMeetings.ReadWrite),而不支持应用程序权限.您可以在上一个说明中看到这一点.
The API(/v1.0) just supports delegated permission(OnlineMeetings.ReadWrite), not application permission. You could see this in the previous note.
/beta
都还仅支持委派权限,请参阅:
Both the /beta
also only supports delegated permission, see:
这篇关于Microsoft Graph OnlineMeeting API返回状态:未找到(404)错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!