Jsonp get the number of Twitter and Facebook articles in concrete steps

Source: Internet
Author: User
Tags require

  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.    

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.