问题
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:
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/
来源:https://stackoverflow.com/questions/29177190/display-number-of-linkedin-shares-client-only-without-authentication