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

前端 未结 12 836
故里飘歌
故里飘歌 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:38

    this is for url with https (for Brodie) https://cdn.api.twitter.com/1/urls/count.json?url=YOUR_URL

    0 讨论(0)
  • 2020-12-22 20:50

    Yes,

    https://share.yandex.ru/gpp.xml?url=http://www.web-technology-experts-notes.in
    

    Replace "http://www.web-technology-experts-notes.in" with "your full web page URL".

    Check the Sharing count of Facebook, Twitter, LinkedIn and Pinterest

    http://www.web-technology-experts-notes.in/2015/04/share-count-and-share-url-of-facebook-twitter-linkedin-and-pininterest.html

    Update: As of 21st November 2015, Twitter has removed the "Tweet count endpoint" API.

    Read More: https://twitter.com/twitterdev/status/667836799897591808

    0 讨论(0)
  • 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);
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <div id="so-url-shares">Calculating...</div>

    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

    0 讨论(0)
  • 2020-12-22 20:55

    No.

    How do I access the count API to find out how many Tweets my URL has had?

    In this early stage of the Tweet Button the count API is private. This means you need to use either our javascript or iframe Tweet Button to be able to render the count. As our systems scale we will look to make the count API public for developers to use.

    http://dev.twitter.com/pages/tweet_button_faq#custom-shortener-count

    0 讨论(0)
  • 2020-12-22 20:57

    I just read the contents into a json object via php, then parse it out..

    <script>
    <?php
    $tweet_count_url = 'http://urls.api.twitter.com/1/urls/count.json?url='.$post_link;
    $tweet_count_open = fopen($tweet_count_url,"r");
    $tweet_count_read = fread($tweet_count_open,2048);
    fclose($tweet_count_open);
    ?>
    var obj = jQuery.parseJSON('<?=$tweet_count_read;?>'); 
    jQuery("#tweet-count").html("("+obj.count+") "); 
    </script>
    

    Simple enough, and it serves my purposes perfectly.

    0 讨论(0)
  • 2020-12-22 20:58

    This is not possible anymore as from today, you can read more here:

    https://twitter.com/twitterdev/status/667836799897591808

    And no plans to implement it back, unfortunately.

    Up vote so users do not lose time trying out.

    Update: It is however possible via http://opensharecount.com, they provide a drop-in replacement for the old private JSON URL based on searches made via the API (so you don't need to do all that work).

    It's based on the REST API Search endpoints. Its still new system, so we should see how it goes. In the future we can expect more of similar systems, because there is huge demand.

    0 讨论(0)
提交回复
热议问题