With 'picture' in Facebook's Feed Dialog deprecated how can I post an image link?

前端 未结 2 481
没有蜡笔的小新
没有蜡笔的小新 2020-12-13 16:14

I\'ve been using Facebook\'s Feed Dialog to let users on a site share content on their Facebook feed. On their feed there would be a picture that serves as a link to the pag

2条回答
  •  攒了一身酷
    2020-12-13 16:32

    You need to use the Open Graph actions method described at the bottom of this page here in the FB dev docs.

    Trigger a Share Dialog using the FB.ui function with the share_open_graph method parameter to share an Open Graph story.

    Try this within your code to specify a custom image, title, description or link on your FB shares:

        // this loads the Facebook API
        (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'));
    
        window.fbAsyncInit = function () {
            var appId = '1937011929814387';
            FB.init({
                appId: appId,
                xfbml: true,
                version: 'v2.9'
            });
        };
    
        // FB Share with custom OG data.
        (function($) {
    
            $('.fb_share_btn').on('click', function (event) {
                event.preventDefault();
                event.stopImmediatePropagation();
    
                    // Dynamically gather and set the FB share data. 
                    var FBDesc      = 'Your custom description';
                    var FBTitle     = 'Your custom title';
                    var FBLink      = 'http://example.com/your-page-link';
                    var FBPic       = 'http://example.com/img/your-custom-image.jpg';
    
                    // Open FB share popup
                    FB.ui({
                        method: 'share_open_graph',
                        action_type: 'og.shares',
                        action_properties: JSON.stringify({
                            object: {
                                'og:url': FBLink,
                                'og:title': FBTitle,
                                'og:description': FBDesc,
                                'og:image': FBPic
                            }
                        })
                    },
                    function (response) {
                    // Action after response
                    })
            })
    
        })( jQuery );
    

提交回复
热议问题