如何从Microsoft Graph搜索查询返回的HitID获取事件ID? [英] How to get an event ID from the HitID returned by a Microsoft Graph search query?
问题描述
我正在尝试使用Microsoft Graph API(来自Node Express应用程序)修补日历事件.
- 我使用
client.api('/me/events').post(myEvent)
创建一个新事件,它的工作原理很好(我看到它出现在我的日历中).返回值的ID为:
由于某些原因,我不明白为什么两个ID并不完全相同: 但是我得到一个错误: 能否请您告诉我如何使补丁起作用(并解释为什么搜索中的ID与所创建的ID并不完全相同).我已经阅读了文档中的几个示例(例如 https://docs.microsoft.com/en-us/graph/search-concept-events ),但找不到解决方案. 非常感谢! 因此,这里发生的是 一种可行的解决方法是用 已经存在在GitHub上发布的问题,以获取有关如何使用 对于两个ID不相同的情况,Graph API将接受两个ID并解析为相同的资源.我不知道为什么他们与众不同. I am trying to patch a calendar event with the Microsoft Graph API (from a Node express app). For some reason I don't understand why the 2 IDs are not fully identical: the
But I get an error: 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, A work around that might work is to replace 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屋! AAMkADc0Yjg2ODdmLTlkNDQtNGQ0Yi1iNjBmLTE1MDdmYzI4MGJkOABGAAAAAADt0ZJy6xMCRq23C8icFGeqBwAOM3XMH4d2SYMQ5psbvFytAAAAAAENAAAOM2
client.api('/search/query').post(myQuery)
根据某些条件查找事件,这很好.我收到一连串的匹配,只有一个匹配(实际上是刚创建的事件,查看主题和正文),并且 hitId
等于: AAMkADc0Yjg2ODdmLTlkNDQtNGQ0Yi1iNjBmLTE1MDdmYzI4MGJkOABGAAAAAADt0ZJy6xMCRq23C8icFGeqBwAOM3XMH4d2SYMQ5psbvFytAAAAAAENAAAOM2> 7B
_
更改为 +
,并且更改了-
到/
.
let newVal = hits [0] .resource//匹配来自搜索查询返回的结果newVal.id = hits [0] .hitId//需要,因为资源"不包含IDclient.api('/me/events/'+ hitId).patch(newVal)
找不到段'B7AAA ='的资源.
PATCH/me/events/{hitId}
由Graph API进行了解析,因此正向 hitId
中的斜线表示路径,并且Graph最终使用 B7AAA =
作为资源ID,因此在段'B7AAA ='中找不到错误 Resource./code>
%252F
替换 hitId
中的/
.您可以这样做.
client.api(`/me/events/$ {hitId.replace('/','%252F')}`)).patch(patch)
/
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=
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=
_
is changed to +
and -
changed to /
.
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)
Resource not found for the segment 'B7AAA='.
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='.
/
in hitId
(s) with %252F
. You can do it like this.client.api(`/me/events/${hitId.replace('/', '%252F')}`).patch(patch)
/