是否有人经历过 FB.ui 的“to”属性被忽略的情况 - 即使它已设置 - 并且帖子仅会发布到当前登录用户的墙上?
当使用使用 FB 示例代码(和硬编码参数值)的完全精简的测试页面时,它会按预期发布到我的墙上。但是当我将“to”属性添加到此 FB 代码时,它仍然仅发布到我的墙上。
任何想法都将不胜感激,因为我已经以我认为彻底的方式搜索了这些文件和 FB 开发网站。
SDK 正确加载并且 iframe 弹出(尽管它滚动到页面顶部)。
这是我的测试页面中使用的精简代码:
$("#well").click(function(e) {
FB.ui(
{
method: 'feed',
to: '***', /* <=== this person is a confirmed friend with appropriate privacy settings */
name: 'The Facebook SDK for Javascript',
caption: 'Bringing Facebook to the desktop and mobile web',
description: (
'A small JavaScript library that allows you to harness ' +
'the power of Facebook, bringing the user\'s identity, ' +
'social graph and distribution power to your site.'
),
link: 'https://developers.facebook.com/docs/reference/javascript/',
picture: 'http://www.fbrell.com/public/f8.jpg'
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);
提前致谢。
# # 更新# #
感谢 Sahil Mittal 的贡献,我找到了这个相当合理的解决方案:
`
var jqxhr = $.get( "http://graph.facebook.com/"+$("#fbto").val()+"?fields=id", function( data ) {
// could do something useful here...
})
.done(function( data ) {
// do something else useful useful, in this case finish posting stuff to the wall
})
.fail(function( data ) {
// thrown if the user doesn't exist
})
.always(function( data ) {
// etc...
})
`
现在,这是一个 jQuery 1.8.* 解决方案,我还应该补充一点,在高流量的情况下,我不确定 FB 会如何善意地敲击他们的 URL 以将提交的用户名转换为 id。但如果我们到达那里,我会很乐意跨过那座桥!
再次感谢萨希尔。
最佳答案
您不能在 to
参数中使用用户名
。您必须使用 id
来代替。
如果您没有 ID,您可以从用户名本身获取 ID。调用 /{username}?fields=id
,您将获得响应中的 ID。
例如:http://graph.facebook.com/sahilmittal?fields=id .
响应是:
{
id: "595273610"
}
只需获取此 id
并在 to
参数中使用它即可。
关于javascript - FB.ui() 忽略 "to"属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23286157/