与查询字符串共享链接

时间:2019-03-07 16:35:38

标签: javascript linkedin query-string sharing social-media

我正在尝试设置一个LinkedIn共享按钮,该按钮需要与包含查询字符串的URL共享。我已经尝试过各种编码URL的组合,但LinkedIn通过删除所有以“ =”开头的内容或共享与“ =”编码为“%3D”的链接“来破坏每个选项

我应该如何解决这个问题,或者LinkedIn不会解决此问题?

我在这里设置了一个简单的演示:https://jsfiddle.net/09dopxm5/

为简便起见,这是我尝试生成可正常使用的链接的Javascript ...

app.post('/', function (req, res, next){

var form = new formidable.IncomingForm(); 
form.hash = 'md5';

form.on('fileBegin', function(name, file){

    file.path = __dirname + '/data/uploaded_files/' + file.name;    
    console.log("File name extracted: " + file.name);
    res.locals.file_name = file.name;

});

form.parse(req, function(err, fields, file) //parsing through body parser
{
    var new_hash = file.hash;
    new_hash = new_hash.digest('hex');
    console.log("Hash generated");
    console.log(new_hash);
});
var original_link = "https://www.simplifyingthemarket.com/en/2019/03/07/why-an-economic-slowdown-will-not-crush-real-estate-this-time/?a=311651-adc5cc7d14b39be55e90ff0b2b7bbf6a";

var link1 = escape(original_link);
var link2 = encodeURI(original_link);
var link3 = encodeURIComponent(original_link);

var linkedinLink = "https://www.linkedin.com/shareArticle?mini=true&url=";

document.getElementById("link-1").href = linkedinLink + link1;
document.getElementById("link-2").href = linkedinLink + link2;
document.getElementById("link-3").href = linkedinLink + link3;
document.getElementById("link-4").href = linkedinLink + original_link;

编辑- 一条补充信息是我们不共享用户当前使用的URL。我们正在尝试分享他们当前正在查看的帖子的个性化版本。

2 个答案:

答案 0 :(得分:0)

这里是使用其API的可能解决方案。 https://jsfiddle.net/yt9hzupw/#&togetherjs=J69Euy0GoC

<script src="//platform.linkedin.com/in.js" type="text/javascript"> lang: en_US</script>
<script type="IN/Share" data-url="http://google.com" data-counter="top"></script>

答案 1 :(得分:0)

您的第三个链接非常适合我!参见:

所以,这意味着解决方案,就JavaScript而言...

var original_link = "https://www.simplifyingthemarket.com/en/2019/03/07/why-an-economic-slowdown-will-not-crush-real-estate-this-time/?a=311651-adc5cc7d14b39be55e90ff0b2b7bbf6a";

var link3 = encodeURIComponent(original_link);
var linkedinLink = "https://www.linkedin.com/shareArticle?mini=true&url=";
document.getElementById("link-3").href = linkedinLink + link3;

您的HTML解决方案是...

<a href='#' id='link-3' target="_blank">Share Attempt 3</a><br/>

如果不确定,可以使用LinkedIn Post Inspector进行检查。

也有帮助: