通过使用Graph API,我可以检索内部和外部Facebook url的评论、点赞数。但是我只能得到外部Facebook url的分享数。
例如:
https://graph.facebook.com/?ids=http://www.youtube.com/watch?v=tu8BNocnVzc
但不是facebook上的:
http://graph.facebook.com/?ids=http://www.facebook.com/photo.php?fbid=364861533533284
如何获取Facebook对象的共享号?
(我可以通过这个url http://graph.facebook.com/364861533533284获得点赞和评论)
发布于 2013-06-07 21:16:04
前面的答案在一件事上是正确的-你应该使用FQL。它的速度较慢,但它是有效的。至于其余部分-它根本不会工作,因为API不会为照片链接返回share_count,因为它是Facebook的内部函数,并且在链接本身或其他未知原因中有PHP参数。
API不会返回这样的信息是不好的,因为它在大多数情况下是公共的,所以他们应该实现它,但是这是不起作用的。
不过,这类工作是检索与该照片连接的帖子链接,并计算其共享。
使用的代码如下:`
$photo_link = $photo['link'];
//First Query - Find the ID of the Post for the Photo
$query_post_id = "SELECT post_id, permalink FROM stream WHERE source_id = '[PAGE_OR_USER_ID]' AND permalink = '$photo_link'";
$fb_post_info = $facebook->api(array('method' => 'fql.query', 'query' => $query_post_id));
$id = $fb_post_info['0']['post_id'];
$whole_id = $fb_post_info['0']['post_id'];
$fb_post_id = explode('_', $id);
$fb_post_id = $fb_post_id['1'];
//Second Query - Find the Share Count Using the Post Link (not the Photo link)
$query_share_count = "SELECT share_count FROM link_stat WHERE url='http://www.facebook.com/[PAGE_OR_PERSONAL_USERNAME]/posts/$fb_post_id'";
$post_info = $facebook->api(array('method' => 'fql.query', 'query' => $query_share_count));
$share_count = $post_info['0']['share_count'];
echo $share_count;
?></span>`第一个查询返回一个包含帖子ID和固定链接的数组。帖子ID看起来像这样: PAGEID_POSTID,例如3333333333_453536456464,所以我们必须拆分它,只得到第二部分,即在固定链接中找到的帖子ID。
之后,我们为post构建链接,通常如下所示:facebook.com/USERNAME/post/POSTID,然后检索该链接的分享计数。在这里,您还可以使用Graph API来获取share_count。
到目前为止,这是我找到的唯一获取信息的方法-它有点草率,因为FQL速度较慢,有时共享的更新在一定时间内不会显示,但正如我所说的-它是有效的。
发布于 2014-06-04 06:49:44
如果照片有相关的帖子和post_id -那么你可以从流表中获得分享计数,否则你将只有链接,评论计数。
post_id还以page_story_id,的形式保存在照片表中
否则,您可以尝试伪造它(连接所有者和对象ids),但现在总是这样,
或者你可以尝试通过源代码+固定链接,或者attachment.media.link,或者created_time (由于棘手的FB行为,在这种情况下使用限制)来查找相关帖子
但我认为如果page_story_id在照片表中是空的,那么就没有任何相关的帖子。
示例(php):
$query = array(
'photoInfo' => "SELECT object_id, aid, album_object_id, comment_info.comment_count, like_info.like_count, page_story_id, concat(owner, '_', object_id), owner, pid, images FROM photo where object_id='{$fbActivity['object_id']}'",
'postInfo' => "SELECT post_id, share_count, like_info.like_count, comment_info.comment_count, message FROM stream WHERE
post_id IN (SELECT page_story_id FROM #photoInfo)
OR post_id IN (SELECT anon FROM #photoInfo)
' //OR (source_id IN (SELECT owner FROM #photoInfo) AND permalink = '{$fbActivity['link']}') LIMIT 999
);
$t = $publicFb->api('/fql', 'GET', array('q' => $query));发布于 2013-01-23 01:42:27
您应该使用FQL并查询照片表https://developers.facebook.com/docs/reference/fql/photo或link_stat表https://developers.facebook.com/docs/reference/fql/link_stat。
下面是如何使用FQL调用来获得结果:
<?php
$img_url='http://www.facebook.com/photo.php?fbid=364861533533284';
$query_url="https://api.facebook.com/method/fql.query?query=
select%20total_count,share_count,like_count,comment_count,
commentsbox_count%20from%20link_stat%20where%20
url='" . $directory_url . "'&format=json";
$response = file_get_contents($query_url);
$response_array = json_decode($response, true);
$params=$response_array[0];
$total_count=$params['total_count'];
$like_count=$params['like_count'];
$comment_count=$params['comment_count'];
$share_count=$params['share_count'];
?>https://stackoverflow.com/questions/9388393
复制相似问题