如何获取 Facebook 上照片的分享次数?

发布于 2025-01-08 10:22:19 字数 696 浏览 0 评论 0原文

通过使用 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 对象的分享数量?

(我可以使用此网址 http://graph.facebook.com/364861533533284 获得点赞和评论)

By using Graph API I can retrieve comments, likes count of both internal and external Facebook url. But I can only get the shares count of external Facebook url

For example:

https://graph.facebook.com/?ids=http://www.youtube.com/watch?v=tu8BNocnVzc

But not a facebook one:

http://graph.facebook.com/?ids=http://www.facebook.com/photo.php?fbid=364861533533284

How can I get the share numbers of a Facebook object?

(I can get likes and comments by using this url http://graph.facebook.com/364861533533284)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

毁虫ゝ 2025-01-15 10:22:19

前面的答案在一件事上是正确的 - 您应该使用 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。

之后,我们为帖子构建链接,通常如下所示:facebook.com/USERNAME/posts/POSTID,然后检索该链接的分享计数。这里你还可以使用Graph API来获取share_count。

这是获取迄今为止我找到的信息的唯一方法 - 这有点草率,因为 FQL 速度较慢,有时共享的更新在一定时间内不会显示,但正如我所说 - 它有点的作品。

The previous answer is correct in one thing - you should use FQL. It's slower but it works. As for the rest - it won't work at all because the API won't return share_count for the photo link because it is an internal for Facebook and has PHP parameters in the link itself or some other unknown reason.

It's not good that the API won't return such information since it's public in most cases so they should implement that but however that doesn't work.

The thing that kind of works though is to retrieve the Post Link connected with that photo and count its shares.

Heres the code used:`

       $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>`

The first query returns an array of the post ID and permalink. The post ID looks like this: PAGEID_POSTID, for example 3333333333_453536456464, so we have to split it to get just the second part which is the post ID found in the permalink.

After that we construct our link for the post which usually looks like this: facebook.com/USERNAME/posts/POSTID and then retrieve the share count for that link. Here you can also use the Graph API to get the share_count.

That's the only way to get the information that I've found till now - it's kind of sloppy because FQL is slower and some times the updates for the shares don't show up for a certain amount of time but as I said - it kind of works.

も星光 2025-01-15 10:22:19

如果照片有相关的帖子和​​ post_id - 那么您可以从 stream 表中获取分享数,否则您将只有链接和评论数。

post_id 也保存在 photo 表中为 page_story_id

否则你可以尝试伪造它(连接所有者和对象 ID),但现在总是这样,

或者你可以尝试查找相关帖子来源+永久链接,或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));

If photo has related post and post_id - then you could get shares count from stream table, otherwise you will have just links, comments count.

post_id also saved in photo table as page_story_id,

otherwise you could try to fake it (concatenating owner and object ids), but it's now always the case,

or you could try find related post by source + permalink, or attachment.media.link, or created_time (use limit in this cases because of tricky FB behavior)

But I think if page_story_id is empty in photo table when there is no any related post.

Example (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));
爱冒险 2025-01-15 10:22:19

您应该使用 FQL 并查询照片表 https://developers.facebook.com/docs/ Reference/fql/photo 或 link_stat 表 https://developers.facebook.com/docs/reference/fql/link_stat..

您可以在此处查看它如何提供结果:http://developers.facebook.com/tools/explorer?fql=SELECT%20url%2C%20normalized_url%2C%20share_count%2C%20like_count%2C%20comment_count%2C%20total_count%2 C%0Acommentsbox_count%2C%20comments_fbid%2C%20click_count%20FROM%20link_stat%20WHERE%20url%3D%22http%3A%2F%2Fwww.facebook.com%2Fphoto.php%3Ffbid%3D364861533533284%22

以下是如何使用 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'];

        ?>

You should use FQL and query the photo table https://developers.facebook.com/docs/reference/fql/photo or link_stat table https://developers.facebook.com/docs/reference/fql/link_stat..

You can see how it delivers the results here: http://developers.facebook.com/tools/explorer?fql=SELECT%20url%2C%20normalized_url%2C%20share_count%2C%20like_count%2C%20comment_count%2C%20total_count%2C%0Acommentsbox_count%2C%20comments_fbid%2C%20click_count%20FROM%20link_stat%20WHERE%20url%3D%22http%3A%2F%2Fwww.facebook.com%2Fphoto.php%3Ffbid%3D364861533533284%22

And here is how you can use the FQL calls to get the result:

    <?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'];

        ?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文