代码之家  ›  专栏  ›  技术社区  ›  dylanT

如何在C中通过Graph API更新用户的邮箱时区#

  •  0
  • dylanT  · 技术社区  · 4 年前

    根据 this link 目前可以通过Graph API更新用户邮箱设置。链接中的示例显示了如何通过C#更新自动回复,并指定了许多可以更新的其他字段,包括时区。

    我正在使用 Microsoft.Graph 3.5.0

    但是,当我尝试运行此代码时:

        public async Task ResetMailboxTimezone(string id)
        {
            // id is a string version of a valid Guid with hyphens
            const string defaultTimezone = "AUS Eastern Standard Time";
            var newUser = new User();
            var mbs = new MailboxSettings
            {
                AdditionalData = new Dictionary<string, object>
                {
                    {"@odata.context", $"https://graph.microsoft.com/v1.0/$metadata#users('{id}')/mailboxSettings"}
                },
                TimeZone = defaultTimezone
            };
            newUser.MailboxSettings = mbs;
    
            await _graphServiceClient.Users[azureGuid].Request().UpdateAsync(userChanges);
        }
    

    我有个例外:

    Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: UpdateMailboxTimezone
     ---> Status Code: MethodNotAllowed
    Microsoft.Graph.ServiceException: Code: ErrorInvalidRequest
    Message: The OData request is not supported.
    Inner error:
            AdditionalData:
            request-id: 246cb7f8-9f33-462c-82f1-3e41fd349053
            date: 2020-05-18T10:12:51
    ClientRequestId: 246cb7f8-9f33-462c-82f1-3e41fd349053
    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)
    

    0 回复  |  直到 4 年前
        1
  •  1
  •   AlfredoRevilla-MSFT    4 年前

    试试这个:

      public async Task ResetMailboxTimezone(string id) {
       const string defaultTimezone = "AUS Eastern Standard Time";
       var mbs = new MailboxSettings {
        AdditionalData = new Dictionary < string, object > {
          {
           "@odata.context",
           $ "https://graph.microsoft.com/v1.0/$metadata#users('{id}')/mailboxSettings"
          }
         },
         TimeZone = defaultTimezone,
       };
    
       // Build your request url
       string requestUrl = $ "https://graph.microsoft.com/v1.0/users/{id}/mailboxsettings";
       var hrm = new HttpRequestMessage(HttpMethod.Patch, requestUrl) {
        Content = new StringContent(_graphServiceClient.HttpProvider.Serializer.SerializeObject(mbs), Encoding.UTF8, "application/json")
       };
    
       // Authenticate (add access token) our HttpRequestMessage
       await _graphServiceClient.AuthenticationProvider.AuthenticateRequestAsync(hrm);
    
       // Send the request
       await _graphServiceClient.HttpProvider.SendAsync(hrm);
      }
    
    推荐文章