javascriptajaxcorssharethis

ShareThis: Social Share Count API returns CORS issue


I am trying to get the repost counters of my articles on social networks via well-known ShareThis service which offers the Social Share Count API. After signing up, registering my domain and installing their script I would like to get numbers of shares via AJAX in JSON format. But when I try to do so, a CORS error is returned. Seems as they don't allow me to use their API this way. I checked my account/settings on their site - nothing suitable to fix this issue. What should I do to make it work? Is it even possible?

The documentation is surprisingly simplistic and even scarce - no mention/statement about such a situation is made. Neither I found an official explanation nor many talks on this issue on the web. I could have done it via CURL on the server side, but I would prefer to use AJAX on the client. Any info?


Solution

  • well, I want to tell that in the end I used the following approach (no JS involved):

    I wrote a PHP-script in which in a cycle I get all the articles' urls and call a simple function getReposts() for each url:

    function getReposts($url) {
        $result = file_get_contents("https://rest.sharethis.com/v1/count/urlinfo?url=" . $url);
        $stats = json_decode($result, true);
        return $stats["total"]["outbound"] ? $stats["total"]["outbound"] : 0;
    }
    

    After sending a query to ShareThis API (getReposts() function) and getting shares count for an article, I just update the corresponding field in my database table for this article.

    That PHP-script is run once a day by cron.