图 API 设置 Sharepoint Online 权限失败

Graph API setting Sharepoint Online permissions failing

我们有一个系统使用后台服务来设置对使用 .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
}

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

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