有没有办法用Koala :: Facebook Gem(RoR)传输所需的参数,以便在FB中发送消息?
如果我尝试
graph.put_connections(page_id, "messages", {recipient: {id: "1000XXXOUTXX"}, message: {text: "Hello"}})
我得到了
Koala :: Facebook :: ClientError:类型:OAuthException,代码:100,消息:(#100)参数收件人是必需的
调试
POST: /16XX_OUT_XX814/messages params: {"recipient"=>{:id=>"1000XXXOUTXX"}, "message"=>{:text=>"Hello"}, "access_token"=>"XX_OUTXX"
根据facebook api描述,我必须发送:
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"
如果我理解来自fb的错误回复,我没有正确地使用考拉发送参数。
感谢您的帮助!
链接
考拉:http://www.rubydoc.info/github/arsduo/koala/Koala%2FFacebook%2FGraphAPIMethods:put_connections
FB-API: https://developers.facebook.com/docs/messenger-platform/send-api-reference
答案 0 :(得分:1)
作为哈希的参数也需要是字符串。以下是将消息作为页面发送的示例:
page_graph = Koala::Facebook::API.new(page.access_token)
#Send new message
page_graph.put_connections(page.id, 'messages', recipient: {id: recipient_id}.to_json, message: {text: "Hello World"}.to_json)