使用Fb.ui feed方法根本不显示消息,也不使用user_prompt_message使用默认消息

时间:2012-04-29 15:22:41

标签: facebook-javascript-sdk message

您好我是Facebook开发新手,并希望使用以下代码发布Feed,但邮件和user_message_prompt不会出现在文本框中。我是否需要在我的应用程序中设置一些内容以允许此操作。我得到的只是默认消息。

我尝试了下面的两种方法,它们都没有显示消息,也没有显示user_message_prompt消息。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
    <title></title>
</head>
<body>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>

        FB.init({ appId: "174009502722096", status: true, cookie: true, xfbml: true });

        function postToFeed() {

        var publish = {
        method: 'feed',
        message: 'Martin Okello presents share',
        caption: 'Visit MartinLayooinc',
        description: (
        'Martin Okello, aka the medallion presents his application'
        ),
        link: 'http://www.martinlayooinc.co.uk',
        picture: 'http://www.martinlayooinc.co.uk/topImages/bigMedallion.jpg',
        user_message_prompt: 'Share MartinLayooinc Software with friends!'
       };

       FB.ui(publish, 
       function(response)
       {
       alert('MartinLayooInc has been posted!!')
       });

       function callback(response) {
       document.getElementById('msg').innerHTML = "Post ID: " + response['post_id'];
       }

       FB.ui(obj, callback);

       }

</script>
    <!--from here-->
    <div id="fb-root">
        <p>
            <a onclick='postToFeed(); return false;'><img src="topImages/facebook_button.png" style="height:20px; width:80px;" />
            </a>
        </p>
        <p id='msg'>
        </p>
    </div>
</body>
</html>
<script type="text/javascript">
    window.fbAsyncInit = function () {
        FB.init({ appId: '174009502722096', status: true, cookie: true, xfbml: true });

        /* All the events registered */
        FB.Event.subscribe('auth.login', function (response) {
            // do something with response
            login();
        });
        FB.Event.subscribe('auth.logout', function (response) {
            // do something with response
            logout();
        });

        FB.getLoginStatus(function (response) {
            if (response.session) {
                // logged in and connected user, someone you know
                login();
            }
        });
    };
    (function () {
        var e = document.createElement('script');
        e.type = 'text/javascript';
        e.src = document.location.protocol +
            '//connect.facebook.net/en_US/all.js';
        e.async = true;
        document.getElementById('fb-root').appendChild(e);
    } ());
</script>

2 个答案:

答案 0 :(得分:4)

我相信他们都被弃用了。现在忽略了message参数,我没有在文档中看到其他参数。显然,Facebook希望用户将自己的消息放入文本字​​段而不是强制或提示。在这里查看主要信息页面:

https://developers.facebook.com/docs/reference/javascript/FB.ui/

以及详细页面:

https://developers.facebook.com/docs/reference/dialogs/feed/

滚动到底部,您将看到支持的参数。希望它对你来说不是改变游戏规则的。

答案 1 :(得分:-1)

你应该做这样的事情

window.fbAsyncInit = function() {FB.init({
appId: '{YOUR APP ID}',
xfbml: true,
version: 'v2.1'
});
};
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {
return;
}
js = d.createElement(s);
js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

function share_prompt() {
FB.ui({
method: 'feed',
name: 'Your App Name',
link: 'https://example.com',
picture: 'http://example.com/img/fbicon.jpg',
caption: 'Your Caption here',
description: 'some sort of your own description',
message: 'Your Message goes here mate'
 });
 }

然后调用下面的函数;

<div><a href="#" onclick="share_prompt()">Click to open your dialog</a>      </div>