facebook 分享计数 - 具有不同 URL 的 FQL 问题

发布于 2024-10-20 14:10:06 字数 457 浏览 4 评论 0原文

我的页面上有一个插件,允许用户在 Facebook 上分享我网站上的文章,但每个 url 都附加了他们的用户 ID。

我想要做的是计算总共享数,而不考虑共享者的用户 ID。

但是我无法让 FQL 工作,因为 where 参数不接受 LIKE 函数。

页面将类似于:

page1.php?sid=2 page1.php?sid=34 page1.php?sid=12

但我想检索 page1.php 的总份额,无论 sid 是什么。

LIKE 函数在 FQL 中不起作用,有人有任何想法吗,因为我正在努力处理

当前的代码:

https:// api.facebook.com/method/fql.que … ge1.php%27

I have a plugin on my page which allows users to share articles on my site on facebook, but each url is appended with their user id.

What I want to do is count the number of total share regardless of the shareers user id.

However I cannot get the FQL to work as the where parameter will not accept the LIKE function..

the pages will be something like:

page1.php?sid=2
page1.php?sid=34
page1.php?sid=12

But I want to retrieve the total shares for page1.php regardless of the sid.

The LIKE function doesnot work in FQL does anyone have any ideas as I am struggling

current code:

https://api.facebook.com/method/fql.que … ge1.php%27

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

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

发布评论

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

评论(1

似最初 2024-10-27 14:10:06

您可以使用 FQL 进行查询:

$fql = 'SELECT total_count FROM link_stat WHERE url="http://google.com"';
$json = file_get_contents('https://api.facebook.com/method/fql.query?format=json&query=' . urlencode($fql));
$data = json_decode($json);
echo $data[0]->total_count;

这里,total_count 为您提供链接的共享数量。

如果您有多个要查询的 URL,则可以使用 OR 在一次查询中完成所有这些操作:

SELECT url, total_count FROM link_stat WHERE url="..." OR url="..."

以下是一个示例,您想要获取这 3 个 URL 的共享数量:

$urls = array(
    "http://www.example.com/page1.php?sid=2",
    "http://www.example.com/page1.php?sid=12",
    "http://www.example.com/page1.php?sid=34",
);

function wrap($url) {
    return 'url="' . $url . '"';
}

$fql = 'SELECT url, total_count FROM link_stat WHERE ';
$fql .= implode(" OR ", array_map("wrap", $urls));

$json = file_get_contents('https://api.facebook.com/method/fql.query?format=json&query=' . urlencode($fql));
$data = json_decode($json);

以及 $data 是一个由 3 个对象组成的数组,其中包含每个 URL 的共享号:

array(4) {
  [0]=> object(stdClass)#2 (2) {
    ["url"]=> string(17) "http://www.example.com/page1.php?sid=2"
    ["total_count"]=> int(1318598)
  }
  [1] => ...
  [2] => ...
  [3] => ...
}

然后您只需遍历该数组即可求和。

希望有帮助!

You can use FQL to make your query :

$fql = 'SELECT total_count FROM link_stat WHERE url="http://google.com"';
$json = file_get_contents('https://api.facebook.com/method/fql.query?format=json&query=' . urlencode($fql));
$data = json_decode($json);
echo $data[0]->total_count;

Here, total_count gives you the number of shares for the link.

If you have several URL to query, you can make all of that in only one query by using OR :

SELECT url, total_count FROM link_stat WHERE url="..." OR url="..."

Here is an example is you want to get the number of shares for theses 3 URLs :

$urls = array(
    "http://www.example.com/page1.php?sid=2",
    "http://www.example.com/page1.php?sid=12",
    "http://www.example.com/page1.php?sid=34",
);

function wrap($url) {
    return 'url="' . $url . '"';
}

$fql = 'SELECT url, total_count FROM link_stat WHERE ';
$fql .= implode(" OR ", array_map("wrap", $urls));

$json = file_get_contents('https://api.facebook.com/method/fql.query?format=json&query=' . urlencode($fql));
$data = json_decode($json);

And $data is an array of 3 objects with the share number for each URL :

array(4) {
  [0]=> object(stdClass)#2 (2) {
    ["url"]=> string(17) "http://www.example.com/page1.php?sid=2"
    ["total_count"]=> int(1318598)
  }
  [1] => ...
  [2] => ...
  [3] => ...
}

Then you just have to go through the array to make a sum.

Hope that helps !

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