This article mainly introduces the way Jsonp gets the number of Twitter and Facebook articles, and needs friends to refer to the following
The original is used by Twitter and Facebook, because the country is strong, so what I find useful is the inside one to get JSONP the tool class . I have a headache that many popular APIs already require authentication to get information. Since I can access these pages and get information, why don't I use some simple code to get and skip validation This step? I think Twitter and Facebook require authentication to get the number of articles, But it turns out that you can get this information through JSONP. Please refer to the steps below. The javascript I will use basic JavaScript to tell you how to do this: code is as follows://Get the number of articles in the Encapsulation object VAR Socialgetter = (function () { /* JSONP: The tool function that gets the script */ the function injectscript (URL) { var script = document.c Reateelement (' script '); Script.async = true; script.src = url; document.body.appendChild (script); } return { getfacebookcount:function (URL, callbackname) { injectscript (' https:// Graph.facebook.com/?id= ' + URL + ' &callback= ' + callbackname); }, gettwittercount:function (URL, Callbackname) { injectscript (' http://urls.api.twitter.com/1/urls/count.json?url= ' + URL + ' &callback= ' + Callbackname); } }; }) (); //callback method function Twittercallback (Result) { result.count && console.log (' The Count is: ', Result.count); nbsp function Facebookcallback (Result) { result.shares && console.log (' The Count is: ', result.shares); } //Call Socialgetter.getfacebookcount (' Http://davidwalsh.name/twitter-facebook-jsonp ', ' Facebookcallback '); socialgetter.gettwittercount (' Http://davidwalsh.name/twitter-facebook-jsonp ', ' Twittercallback '); because there are many lightweight micro-frameworks to handle JSONP, the most important part of this article may be the URL to get the information. Choose your JSONP tools according to your needs and habits! Twitter and Facebook have a number and frequency limit on these requests, so if your site has a lot of traffic, JSONP is likely to be blocked or blocked. A quick solution is to store the article quantity information in Sessionstorage, but this is only a way for individual users. If you run a large site traffic, you'd better choose to crawl the data on the server side and cache it, and automatically refresh within a certain amount of time.