im trying to get wordpress post facebook share count in foreach, but..
<?php
$post_url = the_permalink();
$url_changed = urlencode($post_url);
$json = file_get_contents( 'http://graph.facebook.com/?id=' . $url_changed );
ini_set("allow_url_fopen", 1);
$array = json_decode($json, true);
echo $array['share']['share_count'];
?>
This gives me only to id="" and error
file_get_contents(http://graph.facebook.com/?id=): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request
But if use
$json = file_get_contents( 'http://graph.facebook.com/?id=http://www.google.com' );
Like that, then it works. Does somebody know workaround or how to get it right?
the_permalink()
displays the current URL and not returning the value, use get_permalink()
instead..