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

前端 未结 2 451
没有蜡笔的小新
没有蜡笔的小新 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:31

    Currently (12/2019) you have to use the OG tags set in the URL for the share, so dynamically update the OG tags in your page based on the url...I recommend each object on your page have a url based on params passed in. See this FB bug for an explanation https://developers.facebook.com/support/bugs/1783400898620381/

    0 讨论(0)
  • 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 );
    
    0 讨论(0)
提交回复
热议问题