abemedia / shareCount

A PHP script to fetch the count of social shares, cache the results and output as JSON, JSONP or XML data.
GNU General Public License v2.0
100 stars 35 forks source link

site is echoed #7

Closed srakl closed 9 years ago

srakl commented 9 years ago
    $count = new shareCount;
    $count->url = 'http://www.abc.com/';

    $obj = json_decode($count->get());
    $totalSocialShares = $obj->shares->total; //total social shares

this code when run, echo's my whole pages source code.

public $format = 'json';            // 'json', 'jsonp' or 'xml'

how to get it to just return the json of the shares?

i did this for a fix, not sure its the right way.

i added

case "html":
                $this->format = 'html';
                //header ("Content-Type:text/xml"); 
                break;

to the setFormat() function

and in my config.php

public $format = 'html';            // 'json', 'jsonp' or 'xml'
abemedia commented 9 years ago

Hi,

Since the script was originally designed as a little standalone API that won't work. I will update it to allow it to be used as you intend if I find time at the weekend.

Providing you only want to use it with it's current functionality, why don't you use the hosted service? You can get all the shares like so:

$shares = file_get_contents('https://count.donreach.com/?url=http://9gag.com/');
abemedia commented 9 years ago

Hi again =)

I've made some adjustments to the script to make it more suitable for other uses than a standalone API.

Use the following code to get the shares now:

$count = new shareCount;
$shares = $count->get('http://abc.com');
$total = $shares->total;