如何在线分析facebook api XML来检索“喜欢”数? [英] How to parse facebook api XML online to retrieve 'like' count?
本文介绍了如何在线分析facebook api XML来检索“喜欢”数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经找到了一个通过api.facebook.com在线检索XML文件的方法,其中包含给定页面接收到的喜欢数量。例如:
I've located a method of retrieving an XML file online via api.facebook.com which contains the number of likes a given page has received. For example:
但是,我不知道我如何在PHP应用程序中解析该XML,然后提取喜欢数字,并将其放入一个变量中以使用自己。 / p>
However, I'm not sure how I can parse that XML in my PHP application to then extract the 'like' number and place it into a variable to use myself.
推荐答案
您可以使用内置的 simplexml_load_file(),但由于它不适用于HTTPS,您可以使用CURL和 simplexml_load_string()函数。
You can use the built-in simplexml_load_file() but since it doesn't work with HTTPS you can use CURL and simplexml_load_string() function.
<?php
$url = "https://api.facebook.com/method/fql.query?query=select%20like_count%20from%20link_stat%20where%20url=%27http://mashable.com/2011/03/21/google-chrome-icon/%27&format=xml";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
curl_close($ch);
$xml = simplexml_load_string($data);
print_r($xml);
?>
这篇关于如何在线分析facebook api XML来检索“喜欢”数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文