显示LinkedIn共享数,仅用于客户端,不进行身份验证 [英] Display number of LinkedIn shares, client-only, without authentication

查看:96
本文介绍了显示LinkedIn共享数,仅用于客户端,不进行身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

https://www.linkedin.com /countserv/count/share?url=stackoverflow.com&format=json 正确显示meteor.com的份额数(目前为935).

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);
});

由于返回了X-Content-Type-Options: nosniff标头,我得到了

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.

是否有解决方法(除了通过代理路由请求),还是只是不可能, LinkedIn解决了该问题?

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?

推荐答案

这看起来像是该帖子的副本:

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);

这里有个小提琴来演示: https://jsfiddle.net/z9u20ucm/1/

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

这篇关于显示LinkedIn共享数,仅用于客户端,不进行身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆