Display number of LinkedIn shares, client-only, wi

2019-09-18 04:12发布

https://www.linkedin.com/countserv/count/share?url=stackoverflow.com&format=json correctly shows the number of shares for meteor.com (935 at the moment).

I'm trying to display that number in the client:

$.getJSON('https://www.linkedin.com/countserv/count/share?url=stackoverflow.com&format=json&callback=?', { dataType: "jsonp" }, function (data) {
    alert(data.count);
});

Because of the X-Content-Type-Options: nosniff header being returned, I'm getting the refuse to execute script error in Chrome:

Refused to execute script from 'https://www.linkedin.com/countserv/count/share?url=http://stackoverflow.com&format=json&callback=jQuery210014496755180880427_1426891580561&_=1426891580562' because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled.

Is there a workaround for this (aside routing the request through a proxy), or is it just impossible, as is the case with GitHub, unless LinkedIn fixes the issue?

1条回答
孤傲高冷的网名
2楼-- · 2019-09-18 05:02

This looks like a duplicate of this post: Get LinkedIn share count JSONP

Here's the answer recomended over there:

myCallback = function(data) {
  alert(data.count);
};

var url = "https://www.linkedin.com/countserv/count/share?url=http://stackoverflow.com&format=jsonp&callback=myCallback";
$.getScript(url);

Here's a Fiddle to demonstrate: https://jsfiddle.net/z9u20ucm/1/

查看更多
登录 后发表回答