我正在使用Facebook API在我的Rails应用程序中创建一个发送对话框。我只是使用Facebook在Javascript中推荐的格式(作为HTML中的脚本)。
我的问题是我得到一个:
API Error code 100, invalid parameter, link URL not properly formatted
<script>
function detail(friend_id, user_name, restaurant_name, restaurant_id, articles){
// assume we are already logged in
FB.init({appId: '<%= Facebook::APP_ID.to_s %>', xfbml: true, cookie: true});
FB.ui({
to: friend_id,
method: 'send',
name: user_name +' needs more details about '+ restaurant_name,
picture: 'http://fb-logo-75.png',
link: "<%= Facebook::SITE_URL%>restaurants/"+restaurant_id,
description: '<b>'+user_name + ' needs your help.</b> Add some color to your review of <b>'+restaurant_name+'</b> and help '+articles["object"]+' decide if he should eat there.'
});
}
</script>
请注意:
a) Facebook::SITE_URL根据环境变化。您可能认为这是本地主机的问题。然而,当我整合网站URL的值(这是一个有效的网站,不像localhost),我仍然得到一个错误。然而,我在Heroku上的应用链接
b)当我发布到feed时,无论是从本地主机还是在生产中,我都不会得到错误。问题似乎仅限于发送对话框。
c)当我在另一个URL,如http://www.cnn.com我没有得到一个错误。下面是如何在页面上调用该方法:
<li class = "flat_list_item"><button id="detail_friend" onclick='detail(<%= review.user.fb_id.to_s %>, "<%= @current_user.first_name.to_s %>",
"<%= review.restaurant.name.to_s %>", <%= review.restaurant.id %>,<%= @current_user.gender_article.to_json %>)'>Tell me more</button></li>
注意:用户。Gender_article是一个hack,如果用户是男性,则提供"his/him/he",如果用户是女性,则提供"her/her/hers"。
在客户端是这样翻译的:
HTML:<button id="detail_friend" onclick="detail(XXXX, "Laurent","Refuge", 227,{"subject":"he","possess":"his","object":"him"})">Tell me more</button>
脚本在客户端是这样的:
function detail(friend_id, user_name, restaurant_name, restaurant_id, articles){
// assume we are already logged in
FB.init({appId: 'XXXX', xfbml: true, cookie: true});
FB.ui({
to: friend_id,
method: 'send',
name: user_name +' needs more details about '+ restaurant_name,
picture: 'http://fb-logo-75.png',
link: 'http://powerful-woodland-3700.herokuapp.com',
description: '<b>'+user_name + ' needs your help.</b> Add some color to your review of <b>'+restaurant_name+'</b> and help '+articles["object"]+' decide if he should eat there.'
});
}
请注意,这个链接实际上是一个功能链接(尽管有很多错误-但它确实存在,并且链接到一个实际的网站)
http://fb-logo-75.png的图片URL无效
它必须是一个绝对的url(例如:http://domain.com/path/to/image.png),不能位于Facebook的CDN。所以改成http://your_domain.com/path/to/fb-logo-75.png