使用PHP获取Facebook的赞数
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用PHP获取Facebook的赞数相关的知识,希望对你有一定的参考价值。
Use the facebook api to grab how many \'likes\' a url has had.
<?php // the url to check how many likes $url = 'http://www.likewizard.com/like-67'; // build the facebook query $fburl = "http://api.facebook.com/method/fql.query?query=select%20like_count%20from%20link_stat%20where%20url='$url'&format=atom"; // grab the atom dump via facebook api url call above // it returns something like this: /* <fql_query_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" list="true"> <link_stat> <like_count>9</like_count> </link_stat> </fql_query_response> */ // grab the like count out, i hate dom parsing, so just use regex: $like_count = $matches[1]; echo "The URL $url has $like_count likes on facebook"; // OPTION 2 >>> keeping it to a 1 liner: $data = json_decode(file_get_contents("http://api.facebook.com/method/fql.query?query=select%20like_count%20from%20link_stat%20where%20url='$url'&format=json")); echo "The URL $url has " . $data[0]->like_count . " likes on facebook"; ?>
以上是关于使用PHP获取Facebook的赞数的主要内容,如果未能解决你的问题,请参考以下文章
使用 php sdk 在 facebook 中获取访问令牌时出错