大马资讯论坛 - 马来西亚中文资讯平台

 找回密码
 注册
搜索
打印 上一主题 下一主题

[教学] php facebook取计算like次数,share次数,comment次数

[复制链接]
跳转到指定楼层
1#
发表于 2013-7-7 23:52:03 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
利用facebook的fql,取计算like次数,share次数,comment次数。

以下是php的范例:
  1. <?php
  2.         function facebook_shares($url){

  3.                 $fql  = "SELECT url, normalized_url, share_count, like_count, comment_count, ";
  4.                 $fql .= "total_count, commentsbox_count, comments_fbid, click_count FROM ";
  5.                 $fql .= "link_stat WHERE url = '".$url."'";
  6.                  
  7.                 $apifql="https://api.facebook.com/method/fql.query?format=json&query=".urlencode($fql);
  8.                 $fb_json=file_get_contents($apifql);
  9.                 return json_decode($fb_json);
  10.                  
  11.         }       
  12.           
  13.         $fb = facebook_shares('http://www.freeinfo.com.my/viewthread.php?tid=1574');

  14.         // facebook share count
  15.         echo $fb[0]->share_count . "<br>";
  16.          
  17.         // facebook like count
  18.         echo $fb[0]->like_count . "<br>";
  19.          
  20.         // facebook comment count
  21.         echo $fb[0]->comment_count . "<br>";

  22. ?>
复制代码

手机版|大马资讯论坛  

GMT+8, 2024-4-19 13:16 , Processed in 0.020316 second(s), 13 queries , File On.

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表