【发布时间】:2013-11-02 20:21:56
【问题描述】:
我经营一个摄影网站已经两年多了,并显示了每个图片页面在每张图片下累积的 Facebook 点赞和分享次数的统计数据。
我用来获取此信息并将其放入变量的代码是这样的:
<?php // Get Facebook Stats for Shares Likes Comments etc...
$url = "http://api.facebook.com/restserver.php?method=links.getStats&urls=".urlencode($this->canonicalurl);
$xml = file_get_contents($url);
$xml = simplexml_load_string($xml);
$shares = number_format($xml->link_stat->share_count);
$likes = number_format($xml->link_stat->like_count);
$comments = number_format($xml->link_stat->comment_count);
$total = number_format($xml->link_stat->total_count);
?>
一切都很好,直到今天我从 PHP5.2 切换到 5.4,突然所有的统计数据都不再出现。我已经阅读了一些内容,有些人说我需要设置 allow_url_fopen = 1 但已经设置好了。
有人说这可能与使用 file_get_contents 有关,但我没有得到具体结果。
任何人都可以解释一下可能出了什么问题吗?如果这是罪魁祸首,是否有另一种方法可以在不使用 file_get_contents 的情况下编写上述内容?
谢谢!
【问题讨论】:
标签: php facebook facebook-graph-api file-get-contents json