【问题标题】:Update user profile photo with Microsoft Graph .NET SDK使用 Microsoft Graph .NET SDK 更新用户个人资料照片
【发布时间】:2018-02-08 16:41:28
【问题描述】:

我在使用 Microsoft.Graph .net SDK 在 Microsoft graph 中更新或设置用户个人资料图片时遇到问题。

场景:

存在用户(用户角色)的本机应用程序,包括允许用户更新其个人资料的用户个人资料页面。

已使用 Azure AD v2.0 端点并相应地完成了应用注册。许多租户使用应用程序,因此我们在应用程序注册流程中包含管理员同意流程。

同意的范围是User.ReadWriteDirectory.AccessAsUser.AllDirectory.ReadWrite.AllUser.ReadWrite.All


当使用库上传用户个人资料图片时,我们预计 Content-Typeimage/jpegthe documentation。然而,提琴手将content-type 显示为application/octet-stream

PUT /v1.0/me/photo/$value HTTP/1.1
SdkVersion: Graph-dotnet-1.7.0
Cache-Control: no-store, no-cache
Authorization: bearer //removed//
Content-Length: 1051534
Content-Type: application/octet-stream
Host: graph.microsoft.com
Connection: Keep-Alive

结果很奇怪,因为我认为它的错误是由图表解释的

{
  "error": {
    "code": "ErrorInternalServerError",
    "message":
      "An internal server error occurred. The operation failed., The value is set to empty\r\nParameter name: smtpAddress",
    "innerError": {
      "request-id": "5b549f03-1ce5-4c8c-a393-27aef3ed1a75",
      "date": "2018-02-07T12:32:26"
    }
  }
}

我使用的代码如下所示:

if (_selectedPhoto != null)
{
    using(IRandomAccessStream raStream = await _selectedPhoto.OpenReadAsync())
    {
        await graphClient
            .Me
            .Photo
            .Content
            .Request()
            .PutAsync(raStream.AsStream());
    }
}

此外,我克隆了SDK repository 并运行了单元测试UserUpdatePhoto,结果相同。

对应的方法如下。将内容类型更改为image/jpeg 确实会生成503 unknown error。不知道根本原因是什么。

public System.Threading.Tasks.Task<Stream> PutAsync(Stream content, CancellationToken cancellationToken, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead)
{
    this.ContentType = "application/octet-stream";
    this.Method = "PUT";
    return this.SendStreamRequestAsync(content, cancellationToken, completionOption);
}

【问题讨论】:

  • 错误是报告smtpAddress 丢失。澄清一下,此帐户在 Exchange Online 中是否有有效(和预配的)邮箱?
  • 你是对的!我们检查了一个受影响的邮箱,发现其配置存在问题。重新创建邮箱后,呼叫直接通过。再次感谢!

标签: c# microsoft-graph-api outlook-restapi


【解决方案1】:

根据 cmets,我检查了受影响用户的邮箱,邮箱配置存在问题。因此,问题只是由于缺少邮箱。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-09
    • 1970-01-01
    • 2020-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多