0

我正在使用 Facebook JavaScript SDK 从我的自定义 HTML 表单在不同的 Facebook 用户页面上发布,

我的 HTML 表单包含以下字段

title=>textbox, 
Link url=>textbox, 
picture=>textbox, 
message=>textarea

但我面临的问题是,当用户没有在字段(空白)中输入链接 URL,并在图片 URL 字段框中输入图片 URL 时,facebook 在墙上显示图片主机名称,而不是显示空白或没有链接 URL/图片 URL。 在此处输入图像描述

我用于在页面上发布我的状态的代码

FB.api('/' + d + '/feed', 'post', {
                                message: my_message,
                                link: url,
                                name: title,
                                picture: picUrl,
                                description: desc,
                                access_token: b.access_token
                            }, function (a) {
                                if (!a || a.error) {
                                    alert('Error occured')
                                } else {
                                    alert('Message Posted Successfully.')
                                }
                            })

链接:网址

图片:图片网址

我尝试通过评论“链接”参数提交,但仍然 facebook 在墙上显示图片主机 URL 地址。

所以我需要知道如果用户没有提交链接 URL,如何停止在墙上显示图片主机 URL 地址

4

1 回答 1

0

在 Facebook 帖子中,您可以将此链接称为标题,您只需在标题参数中保留一些空间。如果您使用的是 string.empty,那么它将打印您的 IP 地址/域名。

在这里,我为您提供了示例代码...

<div id="fb-root"></div>
<script>
    window.fbAsyncInit = function () {
        FB.init({
            //Get your Facebook API Key from Web.config
            appId: '<%=ConfigurationManager.AppSettings["FB_API_KEY"].ToString() %>',
            status: true, // check login status
            cookie: true, // enable cookies to allow the server to access the session
            xfbml: true  // parse XFBML
        });
    };

    (function () {
        var e = document.createElement('script');
        e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
        e.async = true;
        document.getElementById('fb-root').appendChild(e);
    }());
</script>

您需要创建 div 以将脚本添加到其中。

现在,我正在从 ServerSide 调用 postToFacebook() 函数,您可以根据需要执行此操作。所以,这就是它的功能。

function postToFacebook() {

    var POST_NAME = "Post Name";
    var POST_DESCRIPTION = "Post Description";
    var POST_MESSAGE = "";


    //Here I am Leaving some space in the Caption to avoid link name
    var POST_CAPTION = "  ";


    var body = 'Reading Connect JS documentation';
    FB.login(function (response) {
        if (response.authResponse) {
            FB.api('/me/feed', 'post', { body: body, message: POST_MESSAGE, caption: POST_CAPTION, name: POST_NAME, description: POST_DESCRIPTION, picture: document.getElementById('hfImageURL').value }, function (response) {
                if (!response || response.error) {
                    //alert(response.error);
                    alert('Image is not posted.');
                } else {
                    alert('Image is posted.');
                }
            });
        }
    }, { scope: 'offline_access,publish_stream' });
}

我将图像 URL 存储到 ID 为 hfImageURL 的 HiddenField 中,并将其提供给 Post 的图片属性。

就是这样,您可以检查该代码...对我来说工作正常...

祝你今天过得愉快...

于 2014-01-28T06:05:45.870 回答