PHP – Facebook – 使用FQL 取得分享、點讚的次數
$fb_appid = "你的APPID";
$fb_secret = "你的APP密碼";
$config['appId'] = $fb_appid;
$config['secret'] = $fb_secret;
$Facebook = new Facebook($config);
$fql = "SELECT click_count,
comment_count,
comments_fbid,
commentsbox_count,
like_count,
normalized_url,
share_count,
total_count,
url
FROM link_stat
WHERE url = 'http://www.wondershow.tw/post_01.php?i=3240' "; //你要查詢的網址
$Fary['method'] = 'fql.query';
$Fary['query'] = $fql;
$LinkInfo = $Facebook->api($Fary);
//print_r($LinkInfo);
/*
* 用Google Chrome 按 F12 查看原始碼,結果應該會是這樣:
Array
(
[0] => Array
(
[click_count] => 0
[comment_count] => 13
[comments_fbid] => 147508702070374
[commentsbox_count] => 0
[like_count] => 28
[normalized_url] => http://www.wondershow.tw/post_01.php?i=3240
[share_count] => 2
[total_count] => 43
[url] => http://www.wondershow.tw/post_01.php?i=3240
)
)
*/
//由FQL的api取得應該會是陣列型態,並沒有經過JSON編碼,所以若我要取得欄位total_count的值:
echo $LinkInfo[0]['total_count']; //會得到 43
// 一般我們看到的分享數字或是點讚的數字,其實是total_count 喔!
//至於實際的點讚數是 like_count; 分享數是 share_count~ 可以自己比對看看
/*以下是關於FQL取得的欄位說明取自於官網 https://developers.facebook.com/docs/reference/fql/link_stat*/
Name | 說明 |
click_count
number |
The number of times Facebook users have clicked a link to the page from a share or like |
comment_count
number |
The number of comments users have made on the shared story |
comments_fbid
number |
The object_id associated with comments plugin comments for this URL. This can be used to query for comments using the comment FQL table |
commentsbox_count
number |
The number of comments from a comments plugin on this URL. This only includestop level comments, not replies |
like_count
number |
The number of times Facebook users have "Liked" the page, or liked any comments or re-shares of this page |
normalized_url
string |
The normalized URL for the page being shared |
share_count
number |
The number of times users have shared the page on Facebook |
total_count
number |
The total number of times the URL has been shared, liked, or commented on |
url ![]() string |
URL of the web page users can share |
ilikeswatch
2013-01-30 - 14:28
哈哈 我昨天也是在GOOGLE查一查查到你的部落格
其實有需要的人一定會看到你寫的東西
真的很有用^^
不好意思歐 我還有一個問題
現在用FQL查回來都是JSON語法
我有甚麼辦法能截他的字串
然後把它塞進資料庫?
因為他回傳的JSON字串我用return_between截不出東西
想說是不是應該要先做JSON_DECODE
可是我一直在試JSON_DECODE感覺越試越複雜
還是JSON本來就可以直接塞資料庫
ilikeswatch
2013-01-30 - 16:43
我的截字串的意思是例如
Array ( [post_id] => 155192654517685_473240949379519 [likes] =>
Array (….
我只想要取得155192654517685_473240949379519然後塞進我MYSQL的
postid欄位
這樣可以直接用FQL的欄位指向MYSQL的欄位塞進去嗎?
ilikeswatch
2013-01-30 - 17:00
謝謝你^^
我來試試看~