如何从Microsoft Graph搜索查询返回的HitID获取事件ID? [英] How to get an event ID from the HitID returned by a Microsoft Graph search query?

查看:47
本文介绍了如何从Microsoft Graph搜索查询返回的HitID获取事件ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Microsoft Graph API(来自Node Express应用程序)修补日历事件.

  1. 我使用 client.api('/me/events').post(myEvent)创建一个新事件,它的工作原理很好(我看到它出现在我的日历中).返回值的ID为:

AAMkADc0Yjg2ODdmLTlkNDQtNGQ0Yi1iNjBmLTE1MDdmYzI4MGJkOABGAAAAAADt0ZJy6xMCRq23C8icFGeqBwAOM3XMH4d2SYMQ5psbvFytAAAAAAENAAAOM2

  1. 然后,我使用 client.api('/search/query').post(myQuery)根据某些条件查找事件,这很好.我收到一连串的匹配,只有一个匹配(实际上是刚创建的事件,查看主题和正文),并且 hitId 等于:

AAMkADc0Yjg2ODdmLTlkNDQtNGQ0Yi1iNjBmLTE1MDdmYzI4MGJkOABGAAAAAADt0ZJy6xMCRq23C8icFGeqBwAOM3XMH4d2SYMQ5psbvFytAAAAAAENAAAOM2> 7B

由于某些原因,我不明白为什么两个ID并不完全相同: _ 更改为 + ,并且更改了-/.

  1. 我现在想修改事件,并尝试用
  2. 进行更新

  let newVal = hits [0] .resource//匹配来自搜索查询返回的结果newVal.id = hits [0] .hitId//需要,因为资源"不包含IDclient.api('/me/events/'+ hitId).patch(newVal) 

但是我得到一个错误:找不到段'B7AAA ='的资源.

能否请您告诉我如何使补丁起作用(并解释为什么搜索中的ID与所创建的ID并不完全相同).我已经阅读了文档中的几个示例(例如 https://docs.microsoft.com/en-us/graph/search-concept-events ),但找不到解决方案.

非常感谢!

解决方案

因此,这里发生的是 PATCH/me/events/{hitId} 由Graph API进行了解析,因此正向 hitId 中的斜线表示路径,并且Graph最终使用 B7AAA = 作为资源ID,因此在段'B7AAA ='中找不到错误 Resource./code>

一种可行的解决方法是用%252F 替换 hitId 中的/.您可以这样做.

  client.api(`/me/events/$ {hitId.replace('/','%252F')}`)).patch(patch) 

已经存在在GitHub上发布的问题,以获取有关如何使用/

处理这些base64编码的资源ID

对于两个ID不相同的情况,Graph API将接受两个ID并解析为相同的资源.我不知道为什么他们与众不同.

I am trying to patch a calendar event with the Microsoft Graph API (from a Node express app).

  1. I create a new event with client.api('/me/events').post(myEvent) and it works just fine (I see it appear in my calendar). The return value has an ID which is:

AAMkADc0Yjg2ODdmLTlkNDQtNGQ0Yi1iNjBmLTE1MDdmYzI4MGJkOABGAAAAAADt0ZJy6xMCRq23C8icFGeqBwAOM3XMH4d2SYMQ5psbvFytAAAAAAENAAAOM3XMH4d2SYMQ5psbvFytAAJ_B-B7AAA=

  1. I then use client.api('/search/query').post(myQuery) to find the event based on some criteria, and this works fine. I receive an array of hits, with only one hit (which actually is the freshly created event, looking at the subject and body), and with a hitId equal to:

AAMkADc0Yjg2ODdmLTlkNDQtNGQ0Yi1iNjBmLTE1MDdmYzI4MGJkOABGAAAAAADt0ZJy6xMCRq23C8icFGeqBwAOM3XMH4d2SYMQ5psbvFytAAAAAAENAAAOM3XMH4d2SYMQ5psbvFytAAJ+B/B7AAA=

For some reason I don't understand why the 2 IDs are not fully identical: the _ is changed to +and -changed to /.

  1. I now want to modify the event, and try to update it with

let newVal = hits[0].resource // hits is coming from the result returned by the search query
newVal.id = hits[0].hitId // needed because the 'resource' does not contain the id
client.api('/me/events/'+hitId).patch(newVal)

But I get an error: Resource not found for the segment 'B7AAA='.

Could you please tell me how to make the patch work (and explain why the ID from the search is not strictly like the one created). I have read several examples in the documentation (such as https://docs.microsoft.com/en-us/graph/search-concept-events) but I could not find a solution.

Many thanks!

解决方案

So what is happening here is, PATCH /me/events/{hitId} is being resolved by Graph API such that the forward slash in the hitId denotes a path and Graph ends up using B7AAA= as a resource id hence the error Resource not found for the segment 'B7AAA='.

A work around that might work is to replace / in hitId(s) with %252F. You can do it like this.

client.api(`/me/events/${hitId.replace('/', '%252F')}`).patch(patch)

There is already this Issue on GitHub for documentation on how to handled these base64 encoded resource ids with /

As for the two IDs being non identical, Graph API will accept both of them and resolve to the same resource. I have no idea why they are different though.

这篇关于如何从Microsoft Graph搜索查询返回的HitID获取事件ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆