如果存在这样的 Facebook 粉丝页面:
https://www.facebook.com/HuffingtonPost
我想通过调用图形 API 来获取点赞数:
https://graph.facebook.com/https://www.facebook.com/HuffingtonPost
事实上我在这里得到:
{
"id": "https://www.facebook.com/HuffingtonPost",
"shares": 435839
}
另一方面,如果我打电话
https://graph.facebook.com/HuffingtonPost
我得到了更详细的输出:
{
"id": "18468761129",
"name": "The Huffington Post",
"picture": "http://profile.ak.fbcdn.net/hprofile-ak-ash2/188072_18468761129_6398033_s.jpg",
"link": "http://www.facebook.com/HuffingtonPost",
"likes": 435832,
"category": "Website",
"website": "http://www.facebook.com/HuffingtonPost",
"username": "HuffingtonPost",
"company_overview": "The Internet Newspaper\nNews | Blogs | Video | Community",
"description": "The Huffington Post - The Internet Newspaper. - Company Overview: The Internet Newspaper News | Blogs | Video | Community | Facebook",
[... omissis ...]
}
谁能告诉我这两个 opengraph 对象有什么区别?
分享数和点赞数之间也存在细微差别。为什么?
更新:
在过去的几天里,graph api 也返回了对象类型,所以我意识到:
- 第一次 API 调用会返回一个 link_stat 类型对象。
- 第二个 API 调用返回页面类型对象。
在第一种情况下,股份数量应代表以下内容的总和:
- 此网址的点赞数
- 此网址的分享次数(包括复制/粘贴链接回 Facebook)
- Facebook 上有关此网址的报道的点赞和评论数量
- 包含此 URL 作为附件的收件箱邮件数量。
在第二种情况下,像 count 只代表它自己
有人可以确认我的分享计数是否正确吗?
最佳答案
对于点赞、分享和评论之间的分割(将它们相加并用作点赞按钮上的“点赞”数量),您最好使用 FQL。
如果您使用 OG,类似 http://graph.facebook.com/http://example.com将向您展示:
{
"id": "http://example.com",
"shares": 3
}
...正如您上面所指出的。如果您使用 FQL,您可以获得每个的分割。
<?php
// require the php sdk
require_once 'facebook-php-sdk/src/facebook.php';
// Create our Application instance.
$facebook = new Facebook(array(
'appId' => 'YOUR_APP_ID',
'secret' => 'YOUR_APP_SECRET',
'cookie' => true,
));
$external_result = $facebook->api(array(
'method' => 'fql.query',
'query' => 'SELECT share_count, like_count, comment_count, total_count, click_count FROM link_stat WHERE url="http://example.com";'
));
echo '<li>'.number_format($external_result[0]['like_count']).' likes, '.number_format($external_result[0]['share_count']).' shares';
echo '<pre>';
print_r($external_result);
echo '</pre>';
?>
这将在屏幕上显示如下内容:
* 1 likes, 2 shares
Array
(
[0] => Array
(
[share_count] => 2
[like_count] => 1
[comment_count] => 0
[total_count] => 3
[click_count] => 0
)
)
此外,SA 现在有一个 Facebook 专用网站,可能会对您有所帮助。 :) facebook.stackoverflow.com
关于Facebook 粉丝页面和相关开放图对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7570671/