26 posts
    Has referred 50+ members Has collected 10+ items on Envato Market Has been part of the Envato Community for over 2 years Located in Vietnam
uxde says
function getPinterestCount() {
    $url = get_permalink();
    $json_string = file_get_contents( 'http://api.pinterest.com/v1/urls/count.json?callback=receiveCount&url='.$url);
    $json = json_decode($json_string, true);
    return intval( $json['count'] );
}

Hi guys, please help me check and fix the following code, I can’t understand why it couldn’t work.

Thanks!

5 posts
    Has been part of the Envato Community for over 4 years Has referred 1+ members Has collected 10+ items on Envato Market Located in United States
myownserver says
function getPinterestCount() {
    $url = get_permalink();
    $json_string = file_get_contents( 'http://api.pinterest.com/v1/urls/count.json?callback=receiveCount&url='.$url);
        if( !$json_string )
            return false;
        $json_string = substr( $json_string, strpos($json_string,'{') );
        $json_string = substr( $json_string, 0, strrpos($json_string,'}')+1 );

    $json = json_decode($json_string, true);
        if( !is_array($json) || !isset($json['count']) )
            return false;

    return intval( $json['count'] );
}

That should work. The problem is it returns a non-valid JSON response, so you have to filter out the extra junk to get a valid JSON string to parse.

26 posts
    Has referred 50+ members Has collected 10+ items on Envato Market Has been part of the Envato Community for over 2 years Located in Vietnam
uxde says

Thank you very much!

by
by
by
by
by
by