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 5 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!

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by