2016-11-18 43 views
1

發送消息。當我從https://developers.facebook.com/docs/messenger-platform/send-api-referenceFacebook發送API - 無法使用用戶ID

curl -X POST -H "Content-Type: application/json" -d '{ 
    "recipient":{ 
    "id":"USER_ID" 
    }, 
    "message":{ 
    "text":"hello, world!" 
    } 
}' "https://graph.facebook.com/v2.6/me/messages?access_token=PAGE_ACCESS_TOKEN" 

我得到這個錯誤執行以下要求:

Graph returned an error: (#100) Parameter recipient[id]: Invalid id: "the id of the recipient" 

的文檔指出:

The id must be an ID that was retrieved through the Messenger entry points or through the Messenger webhooks (e.g., a person may discover your business in Messenger and start a conversation from there. These IDs are page-scoped IDs (PSID). This means that the IDs are unique for a given page. If you have an existing Facebook Login integration, user IDs are app-scoped and will not work with the Messenger platform.

我不明白從哪裏得到id。有人可以解釋如何獲得在API中使用的ID?

+0

你爲用戶使用了什麼ID?你究竟如何得到它?你知道你只能在用戶開始使用你的機器人後才能得到它,對嗎? – luschn

+0

首先設置您的機器人,並與您的Facebook用戶發送消息。 facebook提供了示例代碼,只需查看文檔即可。你只有在用戶與你的機器人交互時纔會得到一個id。用示例代碼做一些測試,你會看到。 – luschn

+0

當用戶發送消息時,您將獲得Page範圍的用戶ID。你不能只是給隨機的人發送消息 – WizKid

回答

1

當用戶給你發消息時,你從webhook獲得用戶標識。此ID不是用戶的ID,而是每個用戶在進入您的頁面時被分配一個唯一的ID。這個ID然後用於在您的頁面和用戶之間進行通信。

+0

userId是否從頁面的feed api或頁面消息的圖形api收到的與這個id相同? –

+0

你有沒有正確的答案我也面臨上述問題? – sunil