简体   繁体   English

Facebook图形api与php-共享计数

[英]facebook graph api with php - share count

im trying to get wordpress post facebook share count in foreach, but.. 我试图在foreach中获取wordpress发布facebook共享数量,但是..

<?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 这只给我id =“”和错误

file_get_contents( http://graph.facebook.com/?id= ): failed to open stream: HTTP request failed! file_get_contents( http://graph.facebook.com/?id= ):无法打开流:HTTP请求失败! HTTP/1.1 400 Bad Request HTTP / 1.1 400错误请求

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.. the_permalink()显示当前URL,但不返回值,请改用get_permalink()

Read more about get_permalink() on WP 阅读有关WP的get_permalink()的更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM