当您将 Outlook 联系人移动到另一个文件夹时,他们的 ID 会发生变化

Outlook contacts change their ID when you move them to another folder

Microsoft Graph Rest 有问题API。我写了一个程序,应该从 Outlook 中读取联系人,然后一次又一次地匹配它们。为此,我使用联系人记录中的 ID。我的程序读取所有文件夹并获取有关所有联系人的必要信息。到目前为止效果很好。

现在我出乎意料地遇到了一个问题,因为 Outlook 中的联系人 ID 可能会更改,因此我失去了对外部数据集的引用。

以下情况给我带来了麻烦。

  1. 我在 Outlook 中创建了一个联系人。这个联系人通过Rest读取出来后就有了ID API.

{'@odata.etag': 'W/"EQAAABYAAADqyc40Bfr0RZDGyWTzcCdWAADu40Xu"', 'id': 'AAMkADE4MWMwOTY4LTM2ODAtNDAyZS1iZDgwLWEyYjE3NTUxY2U4OABGAAAAAACYta-jK-baT5Lfw8NopJJYBwDqyc40Bfr0RZDGyWTzcCdWAADCW0U2AADqyc40Bfr0RZDGyWTzcCdWAADvCEp-AAA=', 'displayName': 'Max Mustermann'}

  1. 我使用联系人的“移动到”选项将其移动到另一个文件夹。之后这个联系人就有了不同的ID。

{'@odata.etag': 'W/"EQAAABYAAADqyc40Bfr0RZDGyWTzcCdWAADu40YP"', 'id': 'AAMkADE4MWMwOTY4LTM2ODAtNDAyZS1iZDgwLWEyYjE3NTUxY2U4OABGAAAAAACYta-jK-baT5Lfw8NopJJYBwDqyc40Bfr0RZDGyWTzcCdWAADvCHYwAADqyc40Bfr0RZDGyWTzcCdWAADvCLTCAAA=', 'displayName': 'Max Mustermann'}

谁能告诉我如何防止这种情况发生? ...或者有没有办法读取联系人的旧 ID?

也许有人可以解释一下,如果我将联系人移动到文件夹,为什么 ID 会发生变化。

欢迎任何帮助。

原因在这里描述:

Outlook items (messages, events, contacts, tasks) have an interesting behavior that you've probably either never noticed or has caused you significant frustration: their IDs change. It doesn't happen often, only if the item is moved, but it can cause real problems for apps that store IDs offline for later use. Immutable identifiers enables your application to obtain an ID that does not change for the lifetime of the item.

https://docs.microsoft.com/en-us/graph/outlook-immutable-id

还有解决方法:

Immutable ID is an optional feature for Microsoft Graph. To opt in, your application needs to send an additional HTTP header in your API requests:

Prefer: IdType="ImmutableId"

This header only applies to the request it is included with. If you want to always use immutable IDs, you must include this header with every API request.

https://docs.microsoft.com/en-us/graph/outlook-immutable-id#how-it-works