首页 > 解决方案 > 图形 API 设置 Sharepoint Online 权限失败

问题描述

我们有一个系统,它使用后台服务来设置使用 .Net Graph SDK 新创建的 SharePoint Online 文档的权限。看似随机,我们的操作失败并返回 UnknownError 响应,我们不确定从那里去哪里。

我们曾尝试按需重现该问题,但我们仅在非交互式后台服务上遇到该问题。后台服务执行此操作的次数比我们能够尝试按需执行的次数要多得多,因此在这种情况下它会发生更多是有道理的。

var driveRecipients = new List<DriveRecipient>();

// Code that adds recipients
// var recipient = new DriveRecipient { Email = "..." };
// driveRecipients.Add(recipient)

var roles = new List<string> { "write" };

var inviteResult = await graphClient
    .Drives[driveId]
    .Items[fileId]
    .Invite(driveRecipients, true, roles, notifyUsers, "Automated SharePoint permission added by app X")
    .Request().PostAsync(cancellationToken);

return inviteResult;

通常,我们会收到一个 IDriveItemInviteCollectionPage 结果,但是当错误发生时,会抛出类似的异常(由于服务是非交互式的,我们只能访问记录的序列化异常):

Exception: {
       Data: [
       ]
       Error: {
         AdditionalData: null
         Code: UnknownError
         InnerError: {
           AdditionalData: {
             date: 2019-09-06T19:08:23.0000000
             request-id: 607a5beb-6742-45c7-893f-9352242c70d4
           }
           Code: null
           InnerError: null
           Message: null
           ThrowSite: null
           _typeTag: Error
         }
         Message:
         ThrowSite: null
         _typeTag: Error
       }
       HResult: -2146233088
       HelpLink: null
       InnerException: null
       Message: Code: UnknownError

Inner error

       ResponseHeaders: [
         {
           Key: Cache-Control
           Value: [
             private
           ]
           _typeTag: KeyValuePair`2
         }
         {
           Key: Transfer-Encoding
           Value: [
             chunked
           ]
           _typeTag: KeyValuePair`2
         }
         {
           Key: request-id
           Value: [
             607a5beb-6742-45c7-893f-9352242c70d4
           ]
           _typeTag: KeyValuePair`2
         }
         {
           Key: client-request-id
           Value: [
             607a5beb-6742-45c7-893f-9352242c70d4
           ]
           _typeTag: KeyValuePair`2
         }
         {
           Key: x-ms-ags-diagnostic
           Value: [
             {"ServerInfo":{"DataCenter":"West US 2","Slice":"SliceC","Ring":"4","ScaleUnit":"000","RoleInstance":"AGSFE_IN_3","ADSiteName":"WUS2"}}
           ]
           _typeTag: KeyValuePair`2
         }
         {
           Key: Duration
           Value: [
             10019.4936
           ]
           _typeTag: KeyValuePair`2
         }
         {
           Key: Strict-Transport-Security
           Value: [
             max-age=31536000
           ]
           _typeTag: KeyValuePair`2
         }
         {
           Key: Date
           Value: [
             Fri, 06 Sep 2019 19:08:22 GMT
           ]
           _typeTag: KeyValuePair`2
         }
       ]
       Source: Microsoft.Graph.Core
       StackTrace:    at Microsoft.Graph.HttpProvider.SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)
   at Microsoft.Graph.BaseRequest.SendRequestAsync(Object serializableObject, CancellationToken cancellationToken, HttpCompletionOption completionOption)
   at Microsoft.Graph.BaseRequest.SendAsync[T](Object serializableObject, CancellationToken cancellationToken, HttpCompletionOption completionOption)
   at Microsoft.Graph.DriveItemInviteRequest.PostAsync(CancellationToken cancellationToken)
   at <...>
   at <...>
       StatusCode: GatewayTimeout
       TargetSite: Void MoveNext()
       _typeTag: ServiceException
}

标签: c#microsoft-graph-apimicrosoft-graph-sdks

解决方案


感谢您提供诊断信息!您的客户端代码不是问题。这可能是暂时的服务器问题。

将您的 Microsoft Graph .NET 客户端库版本升级到版本 1.17.0,因为我们引入了 504 错误自动重试。您应该会看到升级解决了这个问题。如果您不这样做,请告诉我们;t。


推荐阅读