调用/ me / contacts / {id} / photo不会返回eTag

时间:2019-04-12 16:26:40

标签: microsoft-graph

我正在呼叫me/contacts/{id}/photo,响应与defined in the docs不匹配。

根据文档,有两件事与我所看到的不符:

  1. 当联系人没有照片时,它会指出您将收到一个空的json薪水,但是我收到404响应,并返回了此错误

    Code: ErrorItemNotFound
    Message: The specified object was not found in the store.
    
  2. 当有联系人照片时,文章指出将有@odata.mediaEtag,但是我收到的有效载荷却没有。以下是我的回复:

    (*map[string]interface {})(0xc42014a028)((len=5) {
     (string) (len=6) "height": (float64) 360,
     (string) (len=5) "width": (float64) 360,
     (string) (len=14) "@odata.context": (string) (len=243) "https://graph.microsoft.com/v1.0/$metadata#users('REDACTED')/contacts('REDACTED')/photo/$entity",
     (string) (len=23) "@odata.mediaContentType": (string) (len=10) "image/jpeg",
     (string) (len=2) "id": (string) (len=7) "360X360"
    })
    

问题1对我没有影响,因为我可以轻松处理404。我更关心问题#2,因为我想要etag,因此我可以跟踪图像是否已更改,并且仅在更改后才下载。

我能够设置OAuth,使API能够正常运行,并能够根据文档成功下载联系人和照片,所以我不确定自己缺少什么。

1 个答案:

答案 0 :(得分:0)

不同的端点可能返回略有不同的数据(即/me/photo/me/{id}/photo/groups/{id}/photo)。您可以确定的唯一属性是profilePhoto重新指定的资源:

{
  "id": "240X240",
  "height": 240,
  "width": 240
}

您可以使用eTagcontact用于/me/contacts/{id}?$select=id,lastModifiedDateTime本身(在Outlook中更改联系人的照片应显示为对联系人的修改):

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('{id}')/contacts(id,lastModifiedDateTime)/$entity",
    "@odata.etag": "W/\"EQAAABYAAAAiIsqMbYjsT5e/T7KzowPTAAAYc8Bf\"",
    "id": "{id}",
    "lastModifiedDateTime": "2017-09-04T15:54:02Z"
}