26 posts
- Has been a member for 1-2 years
- Bought between 10 and 49 items
- Referred between 50 and 99 users
- 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!
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 been a member for 1-2 years
- Bought between 10 and 49 items
- Referred between 50 and 99 users
- Vietnam
uxde
says
Thank you very much!
