简体   繁体   English

Facebook分享具有动态参数的链接

[英]Facebook share link with dynamic parameters

I need in implement into my SPA Web application (JavaScript + AngularJS) the ability to share URLs that include parameters like: 我需要在SPA Web应用程序(JavaScript + AngularJS)中实现共享URL的能力,这些URL包含如下参数:

http://MyTestSite.com?action=view&docID=12345

or: 要么:

http://MyTestSite.com?action=edit&docID=67890

The page being displayed may include a list with very many documents that may be shared, and I need to attach to each of them the possibility of being shared (where the applicable action would depend on the status of the document). 正在显示的页面可能包含一个列表,其中包含很多可以共享的文档,我需要在每个文档上附加共享的可能性(其中适用的操作取决于文档的状态)。

After a lot of googling it would appear that the only way to go for sharing a link that includes parameters is through the use of Open Graph (though I'm not sure about that). 经过大量的搜寻之后,似乎似乎共享共享包含参数的链接的唯一方法是使用开放图谱(尽管我不确定)。

So, the first question would be: Is this the way to go? 因此,第一个问题是:这是走的路吗?

Assuming that the answer is "YES", how can I update dynamically the action and docID that are defined within the header of the HTML document? 假设答案为“是”,如何动态更新HTML文档标题中定义的操作docID Such update must take place as soon as I click on the share button attached to a specific entry within the page. 这种更新必须在我单击页面中特定条目所附的共享按钮后立即进行。

If the answer to the previous question is "NO" (meaning, the Open Graph is not suitable for sharing a link with parameters), what is the way to implement this? 如果上一个问题的答案为“否”(意味着,开放图不适用于共享带有参数的链接),那么实现此方法的方式是什么?

Thanks in advance for any suggestion. 预先感谢您的任何建议。

The problem is that Facebook crawlers, like most crawlers, won't evaluate any javascript on the page so you will be stuck with initial headers on the first page. 问题在于,与大多数爬虫一样,Facebook爬虫不会评估该页面上的任何JavaScript,因此您将在第一页停留在初始标头上。

I handled this issue before with SPA, but creating a server-rendered page used only for sharing, that page will have the relative headers and will redirect to my application. 我之前使用SPA处理过此问题,但是创建了一个仅用于共享的服务器呈现的页面,该页面将具有相对的标题,并将重定向到我的应用程序。

on the front-end applicaiton 在前端应用程序上

var shareOnFacebook = function(type, autourl) {
   FB.ui({
     method: 'share',
     href: 'http://www.example.com/social/'+type+'/'+autourl,
   }, function(response){

     console.log(response);
  });
};

on the server side 在服务器端

    <!-- do the logic to get the needed data and fill the needed tags -->
    <meta property="og:title" content="{{$model->title}}" />
    <meta property="og:description" content="{{$model->description}}" />
    <meta property="og:image" content="{{$model->image}}" />

    <!-- after create a redirect-->
    <meta http-equiv="refresh" content="0;url='http://www.example.com/{{$redirectHash}}"> 

经过一些工作,更多问题和尝试错误,我找到了此处所述的解决方案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM