1

我正在尝试使用以下代码从 SPO 中获取一些 ListItems:

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.ListItemsCollectionResponse.Value”上的集合类型“Microsoft.Graph.IListItemsCollectionPage”。

我正在使用 .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

我的情况出了什么问题?

4

0 回答 0