5

我在搞乱一个 Angular 应用程序,假设我没有使用任何元标记,我如何使用共享对话框让用户共享我的应用程序页面?

使用旧的提要对话框有效,但已被弃用:

$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.');
                }
            });
    };

因此,即使这可行,我也想以相同的方式使用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.');
                }
            });
    };

有什么提示吗?

4

1 回答 1

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
于 2015-03-05T20:45:48.233 回答