【问题标题】:Koala::Facebook::GraphAPI howto use Messages-Type (FB-Messenger)Koala::Facebook::Graph API 如何使用 Messages-Type (FB-Messenger)
【发布时间】:2017-03-03 14:10:14
【问题描述】:

有没有办法通过 Koala::Facebook Gem (RoR) 传输所需的参数以在 FB 中发送消息?

如果我尝试

graph.put_connections(page_id, "messages", {recipient: {id: "1000XXXOUTXX"}, message: {text: "Hello"}})

我明白了

Koala::Facebook::ClientError: type: OAuthException, code: 100, message: (#100)参数receiver为必填项

调试

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

【问题讨论】:

  • 您需要发送 JSON。
  • 是的,当然,但是考拉通常会为我完成杰森的工作:-),请参阅编辑调试输出。
  • 普通 Graph API 请求不使用 JSON。因此,如果您在这里使用与普通 API 请求相同的方法,那么我怀疑它自己在这里发送 JSON。
  • @Alex 你有没有想过这个问题?我遇到了同样的问题。谢谢!

标签: ruby-on-rails ruby facebook messenger koala


【解决方案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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多