【问题标题】:how to set angularjs single page application for social share如何为社交分享设置angularjs单页应用程序
【发布时间】:2017-09-26 06:08:27
【问题描述】:

我正在尝试使用 Express.js 和 AngularJS 设置与 SPA 的社交共享。 事情是,我想分享动态内容,所以我使用angular-facebook-factory 来获取 Facebook 按钮。按钮工作,参数设置,只是我传递的图像、标题和描述参数永远不会到达 Facebook 共享弹出屏幕。

$scope.shareEvent = function (event) {
        console.log('verify values: ', event.image); // works fine!
        FacebookService.share({
            href: 'http://www.example.com/event/'+event_id+'/', // this value is passed
            title: event.title, // Not shown
            description: event.desc, // Not shown
            image: event.image // Not shown
        }, function (response) {
            $scope.me = response;
            $scope.status = true;
        })
    }

FB 共享从http://www.example.com/ 加载默认值(如和)并使用set href 参数(http://www.example.com/event)。我也尝试了 method: 'feed' ,但没有成功。 我应该在页面上有几个不同的分享按钮,所以我猜 meta og 标签不会这样做......

这是具有 ui-view 数量的 SPA,使用 html5 的 ui-router 工作正常,一切正常。

【问题讨论】:

  • Facebook 正在消除在运行时指定这些值的所有可能性,请参阅developers.facebook.com/docs/apps/… 在请求 URL 时让服务器返回 OG 元数据是唯一可行的方法之后。
  • 所以这肯定意味着我必须使用服务器端缓存才能正确响应?
  • 是的。如果您不想最终实现所有功能,那么 prerender.io 之类的服务可以提供帮助。

标签: angularjs html facebook express


【解决方案1】:

这是因为 Facebook 爬虫无法渲染 JavaScript!

Angular JS 在 SEO 集成方面不太友好。

审查您的代码:

$scope.shareEvent = function (event) {
        console.log('verify values: ', event.image); // works fine!
        FacebookService.share({
            href: 'http://www.example.com/event/'+event_id+'/', // this value is passed
            title: event.title, // Not shown
            description: event.desc, // Not shown
            image: event.image // Not shown
        }, function (response) {
            $scope.me = response;
            $scope.status = true;
        })
    }

you said console.log(event.image);  / Works fine 

原因是一样的,你的浏览器可以渲染 JavaScript。但 Facebook 爬虫无法处理该 javaScript。

【讨论】:

  • 您能详细说明一下吗? Js正在渲染og元标记并渲染href,但不渲染标题和图像?按下分享按钮时爬虫是否访问网站?
  • ogtags 在您直接为它们赋值时起作用。
  • 你能推荐任何解决这个问题的方法吗?
  • 我有一个网站,遇到了同样的问题,我尝试使用社交分享但最终使用默认的 facebook-share 按钮,我仍在寻找解决方案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-08-17
  • 2018-06-30
  • 1970-01-01
  • 2014-02-26
  • 2011-04-27
  • 2013-12-30
  • 1970-01-01
相关资源
最近更新 更多