Display number of LinkedIn shares, client-only, without authentication

一曲冷凌霜 提交于 2019-12-25 04:23:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!