Reputation: 15
is there a way to transmit the needed parameters with Koala::Facebook Gem (RoR) for sending messages in FB?
If i try
graph.put_connections(page_id, "messages", {recipient: {id: "1000XXXOUTXX"}, message: {text: "Hello"}})
i get
Koala::Facebook::ClientError: type: OAuthException, code: 100, message: (#100) The parameter recipient is required
Debug
POST: /16XX_OUT_XX814/messages params: {"recipient"=>{:id=>"1000XXXOUTXX"}, "message"=>{:text=>"Hello"}, "access_token"=>"XX_OUTXX"
According to facebook api description i have to send:
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"
If i understand the error reply from fb correct i´m not sending the parameters correctly with Koala.
Thanks for any help!
Links
Koala: http://www.rubydoc.info/github/arsduo/koala/Koala%2FFacebook%2FGraphAPIMethods:put_connections
FB-Api: https://developers.facebook.com/docs/messenger-platform/send-api-reference
Upvotes: 0
Views: 597
Reputation: 6812
The parameters that are hashes need to be strings as well. Here's an example of sending a message as a page:
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)
Upvotes: 1