Facebook分享:从“feed”到“share_open_graph”

5
我正在处理一个Angular应用程序,假设出于论证目的,我没有使用任何元标签,如何使用Share Dialog让用户分享我的应用程序的页面?使用旧的Feed Dialog虽然可以,但已经被弃用了。
$scope.share = function() {
        FB.ui({
                method: 'feed',
                name: 'This is the name field',
                link: 'The link',
                picture: 'The picture',
                caption: 'The caption',
                description: 'This is the content of the "description" field, below the caption.'
                })
            },
            function(response) {
                if (response && !response.error_code) {
                    console.log('Posting completed.');
                } else {
                    console.log('Error while posting.');
                }
            });
    };

所以尽管这个方法可行,但我希望以同样的方式使用共享对话框,但我还没有想出来。以下是我一直在尝试的方法,请记住我是新手:

$scope.share = function() {
        FB.ui({
                method: 'share_open_graph',
                action_type: 'og.likes',
                action_properties: JSON.stringify({
                    object: {
                        'title': 'The title',
                        'image': 'An image',
                        'url': $scope.shareUrl,
                        'description': 'This is the description',
                    }
                })
            },
            function(response) {
                if (response && !response.error_code) {
                    console.log('Posting completed.');
                } else {
                    console.log('Error while posting.');
                }
            });
    };

有什么提示吗?

2
这与AngularJS几乎没有关系,不是吗? - floribon
1个回答

1
短答案是你不能,必须使用OpenGraph元标签。由于Facebook不理解JavaScript和Angular,因此您必须在服务器端检测Facebook的爬虫并为它们呈现静态页面而不是Angular应用程序。尽管具体实现取决于您的服务器技术,但以下是一般想法:1. 为需要共享的资源设置路由:http://example.com/resources/:id2. 查找用户代理3. 如果它是Facebook的爬虫之一,则获取资源并呈现具有OpenGraph标记和空主体的简单视图。否则,只需呈现Angular应用程序。Facebook的爬虫可以在此处here获得,目前有:1.facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)2.facebookexternalhit/1.13.Facebot

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接