Microsoft Graph API不再返回名称和lastModifiedDateTime

时间:2020-09-18 06:01:06

标签: microsoft-graph-api onedrive

我一直在使用Microsoft Graph API的recent items endpoint,直到昨天它才按this documentation返回文件namelastModifiedDateTime

但是,现在响应中不包含namelastModifiedDateTime,并且似乎不再按lastModifiedDateTime排序(出于明显的原因)。

这是我正在使用的端点-https://graph.microsoft.com/v1.0/me/drive/recent?$select=name,id,remoteItem,lastModifiedDateTime,webUrl&$top=50&$orderBy=lastModifiedDateTime desc

以下是回复:

{
   "@odata.type":"#microsoft.graph.driveItem",
   "id":"01YGW3HF7E7M4TYF74AZAZBXWG7BXHJDI5",
   "remoteItem":{
      "createdDateTime":"2020-09-08T09:54:15Z",
      "id":"01YGW3HF7E7M4TYF74AZAZBXWG7BXHJDI5",
      "lastModifiedDateTime":"2020-09-15T05:18:40Z",
      "name":"Document.docx",
      "size":11381,
      "webDavUrl":"https://firmationpersonal-my.sharepoint.com/personal/utkarsh_firmationpersonal_onmicrosoft_com/Documents/Document.docx",
      "webUrl":"https://firmationpersonal-my.sharepoint.com/personal/utkarsh_firmationpersonal_onmicrosoft_com/_layouts/15/Doc.aspx?sourcedoc=%7B3C39FBE4-FC17-4106-90DE-C6F86E748D1D%7D&file=Document.docx&action=default&mobileredirect=true",
      "createdBy":{
         "user":{
            "displayName":"NotAdmin Dalal",
            "email":"utkarsh@firmationpersonal.onmicrosoft.com"
         }
      },
      "file":{
         "mimeType":"application/vnd.openxmlformats-officedocument.wordprocessingml.document"
      },
      "fileSystemInfo":{
         "createdDateTime":"2020-09-08T09:54:15Z",
         "lastModifiedDateTime":"2020-09-15T05:18:40Z",
         "lastAccessedDateTime":"2020-09-15T06:57:48Z"
      },
      "lastModifiedBy":{
         "user":{
            "displayName":"Utkarsh Dalal",
            "email":"utkarshdalal@firmationpersonal.onmicrosoft.com"
         }
      },
      "parentReference":{
         "driveId":"b!BqfSC_mYxUKYaPxJ673ZaLB_EByxRr1Jkipu7nqJIUrSVsVcfbmBSbJAp1sPfpJ4",
         "driveType":"business",
         "id":"01YGW3HF56Y2GOVW7725BZO354PWSELRRZ"
      },
      "shared":{
         
      },
      "sharepointIds":{
         "listId":"5cc556d2-b97d-4981-b240-a75b0f7e9278",
         "listItemId":"1",
         "listItemUniqueId":"3c39fbe4-fc17-4106-90de-c6f86e748d1d",
         "siteId":"0bd2a706-98f9-42c5-9868-fc49ebbdd968",
         "siteUrl":"https://firmationpersonal-my.sharepoint.com/personal/utkarsh_firmationpersonal_onmicrosoft_com",
         "webId":"1c107fb0-46b1-49bd-922a-6eee7a89214a"
      }
   }
}

更新:通过一些修改,我可以解决此问题。响应似乎总是包含remoteItem,因此我从name字典中提取了lastModifiedDateTimeremoteItem。 我也按remoteItem/lastModifiedDateTime进行订购,而不仅仅是lastModifiedDateTime

我在Python中的代码:

endpoint = "https://graph.microsoft.com/v1.0/me/drive/recent?" \
               "$select=name,id,remoteItem,lastModifiedDateTime,webUrl" \
               "&$top=50&$orderBy=remoteItem/lastModifiedDateTime desc"

response = requests.get(endpoint, headers=header)
events = json.loads(response.content)
for recent_activity in events['value']:
     # Merge the remoteItem dict and the recent_activity dict because sometimes the data is nested in remoteItem
     recent_activity = {**recent_activity, **recent_activity.get('remoteItem', {})}
     activity_modified_datetime = datetime.strptime(recent_activity['lastModifiedDateTime'],
                                                               '%Y-%m-%dT%H:%M:%SZ')
     name = recent_activity['name']

在解决此问题之前只是一种解决方法-可能永远不会解决。

0 个答案:

没有答案