c# - Microsoft Graph OnlineMeeting API 返回状态:NotFound (404) 错误
问题描述
我正在尝试使用以下代码创建在线会议并传递应用注册的所有详细信息。仍然返回 404 错误。
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;
解决方案
如您的代码所示,您使用身份验证代码流获取访问令牌,然后通过 MS Graph API 创建 onlineMeeting。请查看我的代码,它运行良好。
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);
笔记:
authenticationCode :验证码流程需要先获取此代码,然后才能获取 API 的访问令牌。看到这一步,你可以通过浏览器请求url并用用户登录,然后它会响应代码。
权限:要让它工作,您需要添加权限(您的应用程序 -> API 权限 -> MS Graph ->委托权限-> OnlineMeetings.ReadWrite)来创建在线会议,请参见此处。
参考:
关于通过 C# 创建 onlineMeeting 的 Microsoft Graph API:链接
有关使用的示例以及有关代码的AuthorizationCodeProvider
更多详细信息。
更新:
消息:仅测试版支持创建具有应用程序权限的在线会议。
API(/v1.0) 只支持委托权限(OnlineMeetings.ReadWrite),不支持应用程序权限。您可以在之前的注释中看到这一点。
两者/beta
也只支持委派权限,见:
推荐阅读
- postgresql - PostgreSQL 为每个 array_agg 元素创建列而不是逗号分隔
- javascript - 如何使两个音频通道相交?
- typescript - 错误 TS2339:“功能”类型上不存在属性“名称”
- c# - 在保持质量的同时减小图像尺寸
- javascript - 正则表达式不允许开头和结尾的空格
- java - 如何从非活动类中删除 FusedlocationProviderClient 位置更新
- vaadin - 3.0.0.beta 的 Vaadin 上下文菜单添加错误,但适用于 2.1.0
- c# - 为什么这个递归搜索返回不相关的结果?
- c++ - 在 QT 中的两个窗口之间共享 websocket 连接
- javascript - 我可以将 Dart 编译的 JS (JavaScript) 用于静态网站的 Firebase 托管吗