MS GraphServiceClient在SharePoint中添加事件列表项获取无效参数

发布于 2025-02-10 05:14:30 字数 1382 浏览 1 评论 0 原文

C#代码(下)是我正在测试的。获得权限等。获取列表项目测试正在工作。在下面的ListItem对象中,ADDASYNC方法具有以下有效载荷,即获得无效的参数。标题,开始时间和结束时间是必需的字段。我无法在事件列表上找到MS Graph的任何特定内容。我正在使用ListItem对象,但不确定其中的不良论点是什么。任何帮助都将受到赞赏。请指教。 tia

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

        // using Azure.Identity;
        var options = new TokenCredentialOptions
        {
            AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
        };

        var clientSecretCredential = new ClientSecretCredential(
            _graphSettings.TenantId, _graphSettings.ClientId, _graphSettings.ClientSecret, options);
        
        _graphClient = new GraphServiceClient(clientSecretCredential, _scopes);


        var listItem = new ListItem
        {
            Fields = new FieldValueSet
            {
                AdditionalData = new Dictionary<string, object>()
                {
                    {"Title", "MS Graph API Test"},
                    {"Description", "Proof of Concept Test"},
                    {"Location", "East Club" },
                    {"Start Time", "2022–06–28T09:00:00" },
                    {"End Time", "2022–06–28T15:00:00" }
                }
            }
        };

        await _graphClient.Sites["{_graphSettings.SharepointSiteId}"].Lists["{_graphSettings.EventListId}"].Items
            .Request()
            .AddAsync(listItem);

The c# code (below) is what I am testing with. Getting by permissions, etc. Get List Item test is working. There AddAsync method with the following payload in the ListItem object below is getting the invalid argument. The Title, Start Time and End Time are required fields. I am unable to find anything specific on event list date formats for MS graph. I am using the ListItem object but not sure what is the bad argument in it. Any help is appreciated. Please advise. TIA

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

        // using Azure.Identity;
        var options = new TokenCredentialOptions
        {
            AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
        };

        var clientSecretCredential = new ClientSecretCredential(
            _graphSettings.TenantId, _graphSettings.ClientId, _graphSettings.ClientSecret, options);
        
        _graphClient = new GraphServiceClient(clientSecretCredential, _scopes);


        var listItem = new ListItem
        {
            Fields = new FieldValueSet
            {
                AdditionalData = new Dictionary<string, object>()
                {
                    {"Title", "MS Graph API Test"},
                    {"Description", "Proof of Concept Test"},
                    {"Location", "East Club" },
                    {"Start Time", "2022–06–28T09:00:00" },
                    {"End Time", "2022–06–28T15:00:00" }
                }
            }
        };

        await _graphClient.Sites["{_graphSettings.SharepointSiteId}"].Lists["{_graphSettings.EventListId}"].Items
            .Request()
            .AddAsync(listItem);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一个人的夜不怕黑 2025-02-17 05:14:30
  • 在以编程方式尝试之前,请尝试在
  • 请确保您将Microsoft Graph API权限授予
    操作前将其写入SharePoint网站。

给出 sites.ReadWrite.all 应用程序许可,如果是用户,请确保sites.readwrite.All授予授权权限。

还请确保同时授予permissions。
检查是否需要在请求标题中给出content_type。

尝试不给出开始和结束日期。

注意:请与SiteID和ListID进行重新检查

参考重新检查: listItem-create |微软文档

  • Before trying it programmatically, try working on the Microsoft
    Graph Explorer
  • Please make sure you are giving Microsoft graph api permissions to
    write to the sharepoint site before operation.

give Sites.ReadWrite.All Application permission , if it is user make sure Sites.ReadWrite.All delegated permission is given.
enter image description here

Also make sure to grant permsissions for the same.
Check if Content_Type needs to be given in request headers.

try without giving start and end date.

Note:Please recheck with the siteId and ListId

Reference: listitem-create | microsoft docs

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文