I am doing the following in a Facebook Request:
function sendRequests() {
FB.ui({
method: 'apprequests',
message: "You are invited to开发者_StackOverflow社区 the surprise Birthday",
data:{"board_id":<%=@board.id%>}
When I get the request object from the user who accepted the application I parse it as a JSON object as follows:
ActiveSupport::JSON.decode(request_body.body)
All of the information is formatted as a Hash should in Rails except for the data I sent in which looks as follows:
"data"=>"{\"board_id\":1}"
I have tried all kinds of combinations but it just won't convert properly. Am I missing something or does the JSON returned by the facebook graph api need to be formatted differently?
Try copying the data and validating it manually here: http://jsonlint.com/
It has helped me numerous times.
In the end I did the following:
In the facebook fb.ui
FB.ui({
method: 'apprequests',
exclude_ids: <%=@invited_guests.map{|guest| guest.provider_user_id} %>,
message: <%="'You are invited to the surprise Birthday board for #{@board.bp_name}'" %>,
title: "Come celebrate with us",
data: "board_id:<%=@board.id%>"
Then in the controller after the request is accepted in facebook:
request_content = ActiveSupport::JSON.decode(request_body.body)
board = ActiveSupport::JSON.decode(request_content["data"])
I have to decode twice. Once for the whole request and the second time for the specific data information passed. It might not be pretty but it works.
精彩评论