【问题标题】:Facebook sharing: going from 'feed' to 'share_open_graph'Facebook 分享:从 'feed' 到 'share_open_graph'
【发布时间】:2014-08-06 04:05:04
【问题描述】:

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

使用旧的 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.');
                }
            });
    };

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

有什么提示吗?

【问题讨论】:

  • 这个和angularjs关系不大吧

标签: facebook angularjs sharing facebook-graph-api-v2.0


【解决方案1】:

简短的回答是不能,必须使用 OpenGraph 元标记。

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

虽然具体实现会因您的服务器技术而异,但总体思路如下:

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

Facebook 的爬虫可用here,它们目前是:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多