0

嗨,我是 facebook 开发的新手,想使用下面的代码发布提要,但消息和 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>
4

2 回答 2

4

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

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

和这里的详细页面:

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

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

于 2012-06-13T13:53:38.350 回答
-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>
于 2014-10-08T14:33:45.203 回答