简体   繁体   English

FB.ui()忽略“ to”属性

[英]FB.ui() ignoring the “to” property

Has anyone experienced the situation where the "to" property of FB.ui gets ignored - even if it's set - and the post only goes to the wall of the currently logged in user? 有没有人遇到过FB.ui的“ to”属性被忽略的情况(即使已设置),并且帖子出现在当前登录用户的墙上吗?

When working with a completely stripped down test page that uses the FB sample code (and hard-coded parameter values) it posts to my wall as expected. 当使用FB示例代码(以及硬编码的参数值)处理完全精简的测试页时,它会按预期发布到我的墙上。 But when I add "to" property to this FB code, it still only posts to my wall. 但是,当我在此FB代码中添加“ to”属性时,它仍然仅发布到我的墙上。

Any ideas would be greatly appreciated, as I have trawled these archives and the FB dev site in what I believe to be a thorough way. 任何想法都将不胜感激,因为我以我认为是彻底的方式来拖曳了这些存档和FB开发站点。

The SDK loads properly and the iframe pops up (though it scrolls to the top of the page). SDK会正确加载,并且会弹出iframe(尽管它会滚动到页面顶部)。

Here's the stripped down code used in my test page: 这是我的测试页中使用的简化代码:

$("#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.');
    }
  }
);

Thanks in advance. 提前致谢。

# # UPDATE # # ##更新##

Thanks to Sahil Mittal's contributions I worked out this fairly reasonable solution: 感谢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... 
})

` `

Now, this is a jQuery 1.8.* solution, and I should also add that in a high-traffic scenario I'm not sure how kindly FB would take to hammering on their URL to convert submitted usernames to ids. 现在,这是一个jQuery 1.8。*解决方案,我还应该补充一点,在交通繁忙的情况下,我不确定FB会如何认真对待其URL,以将提交的用户名转换为ID。 But that's a bridge I'll happily cross if we get there! 但是,如果我们到达那座桥,我会很乐意过桥!

Thanks again to Sahil. 再次感谢Sahil。

You cannot use username in the to parameter. 您不能在to参数中使用username You have to use id instead. 您必须改用id

If you dont have the id, you can get that from the username itself. 如果您没有该ID,则可以从用户名本身获取。 Make the call /{username}?fields=id and you'll get the id in response. 拨打电话/{username}?fields=id ,您将获得ID作为响应。

For eg: http://graph.facebook.com/sahilmittal?fields=id . 例如: http : //graph.facebook.com/sahilmittal?fields=id

The response is: 响应为:

{
  id: "595273610"
}

Just get this id and use it in the to parameter. 只需获取此id ,然后在to参数中使用它to

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM