Is there a way to get the twitter share count for a specific URL?

前端 未结 12 880
故里飘歌
故里飘歌 2020-12-22 20:04

I looked through the API documentation but couldn\'t find it. It would be nice to grab that number to see how popular a url is. Engadget uses the twitter share button on a

12条回答
  •  没有蜡笔的小新
    2020-12-22 20:52

    You can use the following API endpoint,

    http://cdn.api.twitter.com/1/urls/count.json?url=http://stackoverflow.com
    

    Note that the http://urls.api.twitter.com/ endpoint is not public.)

    The endpoint will return a JSON string similar to,

    {"count":27438,"url":"http:\/\/stackoverflow.com\/"}
    

    On the client, if you are making a request to get the URL share count for your own domain (the one the script is running from), then an AJAX request will work (e.g. jQuery.getJSON). Otherwise, issue a JSONP request by appending callback=?:

    jQuery.getJSON('https://cdn.api.twitter.com/1/urls/count.json?url=http://stackoverflow.com/&callback=?', function (data) {
        jQuery('#so-url-shares').text(data.count);
    });
    
    
    Calculating...

    Update:

    As of 21st November 2015, this way of getting twitter share count, does not work anymore. Read more at: https://blog.twitter.com/2015/hard-decisions-for-a-sustainable-platform

提交回复
热议问题