我正在使用 Httparty gem向facebook图表api发送帖子请求 我的代码是
message_data ={
"recipient" => {
"id" => recipient_id
},
"message" => {
"attachment" => {
"type" => "template",
"payload" => {
"template_type" => "generic",
"elements" => [
{
"title" => "Titilize",
"subtitle" => "Subtitle"
}
]
}
}
}
}
options ={
"query": {access_token: @page_access_token},
"body": message_data
}
HTTParty.post("https://graph.facebook.com/v2.6/me/messages",options)
Httparty 会通过将哈希转换为json来发送数据
问题是在结束点数据的接收方式与我预期的不同(可能 httparty 未正确解析)。
有人帮我这个。
感谢
答案 0 :(得分:0)
好像你必须设置Content-Type
标题。根据您的Ruby版本,Hash语法可能存在问题,因此请查看此打开的票证:https://github.com/jnunemaker/httparty/issues/472
str = "{\"recipient\":{\"id\":\"1291831200828847\"},\"message\":{\"attachment\":{\"type\":\"template\",\"payload\":{\"template_type\":\"generic\",\"elements\":[{\"title\":\"Titilize\",\"subtitle\":\"Subtitle\"}]}}}}"
options {
:headers => {"Content-Type" => "application/json"},
:query => {access_token: @page_access_token},
:body => str
}
HTTParty.post("https://graph.facebook.com/v2.6/me/messages", options)