Получить элементы списка SPO через Microsoft Graph SDK для. net не удается с исключением: System.NotSupportedException - PullRequest
1 голос
/ 21 июня 2020

Я пытаюсь получить некоторые ListItems из SPO, используя следующий код:

using Microsoft.Graph;
using Microsoft.Graph.Core;
using Microsoft.Graph.Auth;
using Newtonsoft.Json;
using System;
using System.Security.Principal;
using System.Threading.Tasks;
using Microsoft.Identity.Client;
using System.Collections.Generic;

namespace TPO_List_Access_Using_Graph_SDK
{
    class Program
    {
        static void Main(string[] args)
        {
            AsyncMain().GetAwaiter().GetResult();
            Console.Read();
        }

        static async Task AsyncMain()
        {
            IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder
                .Create("...")
                .WithTenantId("...")
                .WithClientSecret("...")
                .Build();
            var authProvider = new ClientCredentialProvider(confidentialClientApplication);
            var graphClient = new GraphServiceClient(authProvider);

            var queryOptions = new List<QueryOption>()
            {
                new QueryOption("expand", "fields(select=Start,Ende)")
            };

            IListItemsCollectionPage items = await graphClient
                .Sites["pubt.sharepoint.com:/sites/leistungserfassung:"]
                .Lists["Leistungen"]
                .Items
                .Request()
                .Expand("fields")
                .GetAsync();
            
            
            Console.WriteLine(items);
            Console.WriteLine();
            Console.Read();
        }
    }
}

Если я пытаюсь запустить код, возникает исключение:

System.NotSupportedException Тип коллекции Microsoft.Graph.IListItemsCollectionPage в Microsoft.Graph.ListItemsCollectionResponse.Value не поддерживается.

Я использую. net core 3.1 и следующие пакеты, поэтому вот .csproj:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <RootNamespace>TPO_List_Access_Using_Graph_SDK</RootNamespace>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Graph" Version="3.8.0" />
    <PackageReference Include="Microsoft.Graph.Auth" Version="1.0.0-preview.5" />
    <PackageReference Include="Microsoft.Graph.Core" Version="2.0.0-preview.3" />
    <PackageReference Include="Microsoft.Identity.Client" Version="4.15.0" />
    <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
    <PackageReference Include="System.Security.Principal" Version="4.3.0" />
  </ItemGroup>

</Project>

В Graph Explorer я попытался отправить следующий запрос, который успешно завершился:

GET https://graph.microsoft.com/v1.0/sites/pubt.sharepoint.com:/sites/leistungserfassung:/lists/Leistungen/items?$expand=fields

Что не так в моем случае?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...