因此,当我的页面收到消息时,webhook会向我发送以下更改事件:
{
"object":"page",
"entry":
[{"id":"718511138248476","time":1470310180982,
"messaging":
[{"sender":{"id":"845775748857562"},
"recipient":{"id":"718511138248476"},
"timestamp":1470310180901,
"message":
{"mid":"mid.1470310180891:612cfb6aead5fca278",
"seq":468,
"text":"hello"}
}]
}]}
但是,我应该如何知道实际是哪个用户在发送这条消息呢?有没有办法用sender.ID获取用户的facebook ID?
对于第二个问题:sender.id总是一样还是会被更改?我的意思是,当我打算稍后向用户发送消息时,将sender.id保存在数据库中明智吗?
您可以在此处阅读文档https://developers.facebook.com/docs/messenger-platform/user-profile。但是响应字段没有"id"。
Facebook有匹配API的ID,你应该试试https://developers.facebook.com/docs/facebook-login/guides/advanced/id-matching