【发布时间】:2021-12-27 19:45:38
【问题描述】:
我正在使用Microsoft.Graph 进行一些Sharepoint 操作,我们以列出活跃用户为例。考虑一下我正在使用的以下 sn-ps:
public async Task<IList<User>> GetUsers()
{
GraphServiceClient graphClient = await GetGraphServiceClient();
var users = await graphClient.Users.Request().GetAsync();
return users;
}
GetGraphServiceClient 方法创建Microsoft.Graph.GraphServiceClient 的实例,其定义如下:
public async Task<GraphServiceClient> GetGraphServiceClient()
{
return new GraphServiceClient(new DelegateAuthenticationProvider(async (requestMessage) =>
{
requestMessage.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", await GetAccessToken());
}));
}
我得到了一个有效的访问令牌,但是await graphClient.Users.Request().GetAsync(); 行抛出了一个错误,上面写着
找不到方法:'Void Microsoft.Graph.BaseRequest.set_Method(System.String)'。
堆栈跟踪
在 Microsoft.Graph.GraphServiceUsersCollectionRequest.d__4.MoveNext() 在 System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine) 在 Microsoft.Graph.GraphServiceUsersCollectionRequest.GetAsync(CancellationToken cancelToken) 在 Microsoft.Graph.GraphServiceUsersCollectionRequest.GetAsync() 在 myNamespace.GraphAPIHelper.d__3.MoveNext()
以下是项目中使用的 graphSDK 和 SharePoint 客户端的版本:
有人可以帮我确定导致问题的原因吗?我已经交叉检查并验证了租户 ID、客户端 ID 和访问令牌。有些东西不见了,但没有得到任何线索。
【问题讨论】:
标签: c# .net sharepoint microsoft-graph-api sharepoint-online