3

我正在使用 JS-API 生成一个对话框,请求允许发布我的应用程序生成的状态消息。下面是我正在谈论的屏幕截图:

被浏览器阻止的弹出窗口

这是代码:

FB.ui(
   {
     method: 'feed',
     name: 'Facebook Dialogs',
     link: 'http://developers.facebook.com/docs/reference/dialogs/',
     picture: 'http://fbrell.com/f8.jpg',
     caption: 'Reference Documentation',
     description: 'Dialogs provide a simple, consistent interface for applications to interface with users.',
     message: 'Facebook Dialogs are easy!'
   },
   function(response) {
     if (response && response.post_id) {
       alert('Post was published.');
     } else {
       alert('Post was not published.');
     }
   }
 );

我使用文档中所述的示例 JS 代码,如果在浏览器设置中没有阻止弹出窗口,它会很好地工作。但是如果没有显示状态消息,则该应用程序没有实用程序!

请帮忙; 我被困在最后一个阶段。

4

3 回答 3

3

我不明白为什么它会打扰你。如果用户阻止了 FACEBOOK 弹出窗口,那么这是他的损失!

无论如何,如果您确实需要处理所有情况,那么您可以选择不同的方式。阅读提要对话框

您可以做的是,当您完成上一步后,您将页面重定向到 Facebook 提要方法,以便它将作为页面打开:

http://www.facebook.com/dialog/feed?
  app_id=123050457758183&
  link=http://developers.facebook.com/docs/reference/dialogs/&
  picture=http://fbrell.com/f8.jpg&
  name=Facebook%20Dialogs&
  caption=Reference%20Documentation&
  description=Dialogs%20provide%20a%20simple,%20consistent%20interface%20for%20applications%20to%20interact%20with%20users.&
  message=Facebook%20Dialogs%20are%20so%20easy!&
  redirect_uri=http://www.example.com/response

此处要更改的重要部分是app_idand redirect_uri,因此您的代码如下所示:

...
previous code
...
inside previous code success response
...
var url = "http://www.facebook.com/dialog/feed?" +
            "app_id=" + YOUR_APP_ID + "&" +
            "link=http://developers.facebook.com/docs/reference/dialogs/&" +
            "picture=http://fbrell.com/f8.jpg&" +
            "name=Facebook%20Dialogs&" +
            "caption=Reference%20Documentation&" +
            "description=Dialogs%20provide%20a%20simple,%20consistent%20interface%20for%20applications%20to%20interact%20with%20users.&" +
            "message=Facebook%20Dialogs%20are%20so%20easy!&" +
            "redirect_uri=" + YOUR_REDIRECT_URI;
top.location.href = url;
于 2011-03-23T18:41:04.163 回答
1

你的代码很好。它为我打开了 Feed 对话框。你的问题在别的地方。你加了<div id="fb-root"></div>吗?<body>确保它位于标签之后的页面顶部。

还要确保正确加载 FB Javascript SDK:

<script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script>
于 2011-08-19T18:46:53.323 回答
0

使用此代码您忘记添加显示属性

FB.ui(
   {
     method: 'feed',
     display: 'popup',
     name: 'Facebook Dialogs',
     link: 'http://developers.facebook.com/docs/reference/dialogs/',
     picture: 'http://fbrell.com/f8.jpg',
     caption: 'Reference Documentation',
     description: 'Dialogs provide a simple, consistent interface for applications to interface with users.',
     message: 'Facebook Dialogs are easy!'
   },
   function(response) {
     if (response && response.post_id) {
       alert('Post was published.');
     } else {
       alert('Post was not published.');
     }
   }
 );
于 2014-01-22T13:59:25.127 回答