Facebook分享:从'feed'转到'share_open_graph'

ata*_*x1c 5 facebook sharing angularjs facebook-graph-api-v2.0

我正在搞乱一个Angular应用程序,让我们说为了争论我没有使用任何元标记,我如何使用Share Dialog让用户共享我的应用程序的页面?

使用旧的Feed对话框可以使用,但已弃用:

$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.');
                }
            });
    };
Run Code Online (Sandbox Code Playgroud)

所以即使这样可行,我也想以同样的方式使用Share Diolog,但我并没有把它弄清楚.这是我一直在尝试的,请记住,我是一个新手:

$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.');
                }
            });
    };
Run Code Online (Sandbox Code Playgroud)

任何提示?

Pie*_*eau 1

简而言之,你不能,你必须使用 OpenGraph 元标记。

由于 Facebook 不理解 JavaScript,因此也不理解 Angular,因此您必须在服务器端检测 Facebook 的爬虫并为它们呈现静态页面,而不是 Angular 应用程序。

虽然具体的实现会根据您的服务器技术而有所不同,但总体思路如下:

  1. 为需要共享的资源设置路由:http://example.com/resources/ :id
  2. 寻找用户代理
  3. 如果它是 Facebook 的爬虫之一,请获取资源并渲染一个带有 OpenGraph 标签和空正文的简单视图。否则,只需渲染 Angular 应用程序即可。

Facebook 的爬虫程序可在此处使用,目前它们是:

  • facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)
  • facebookexternalhit/1.1
  • Facebot