0

我正在尝试获取过去几天用户的 facebook 朋友共享的最新链接。假设在过去 7 天:

使用 FQL,我一次最多可以为 20 个朋友抓取这个:

$fql = "SELECT link_id, owner, created_time, title, summary, url, image_urls FROM link WHERE owner IN (select uid2 from friend where uid1 = me() LIMIT 20) AND created_time >= $_7ago";

如果我将好友计数限制从 20 设置为更高的值,则查询会崩溃。我目前的解决方案是重复这个查询,在一个循环中将 1000 个朋友分成 20 个一组。这确实有效,但运行时间超过五分钟。

我也尝试过以这种方式进行多查询(速度并没有提高):

"links":"select uid2 from friend where uid1 = me() LIMIT 20",
"stats":"SELECT owner, owner_comment, title, summary, url, image_urls FROM link WHERE owner IN (select uid2 from #links) AND created_time  >= \"' . $_7ago . '\""

有更快的替代方案/解决方案吗?

http://www.pixable.com/ <- 设法在不到 3 秒的时间内提取朋友分享的每月照片

4

1 回答 1

0

多查询也可用于触发多个不相关的查询。首先获取朋友的 uid,然后通过将 uid 分片成块来创建单独的查询,并立即触发所有查询。在 js sdk 中,这看起来像:

FB.api( {
    method: 'fql.multiquery',
    queries: [
            'SELECT owner, owner_comment, title, summary, url, image_urls FROM link WHERE owner IN ('+chunk0+') AND created_time  >= '+time,
            'SELECT owner, owner_comment, title, summary, url, image_urls FROM link WHERE owner IN ('+chunk1+') AND created_time  >= '+time,
            'SELECT owner, owner_comment, title, summary, url, image_urls FROM link WHERE owner IN ('+chunk2+') AND created_time  >= '+time
     ]}, function(results) {
     console.log(results); // array with the individual query results
         var query_results = null;
         var row = null;
         for (var i = 0, l = results.length; i < l; ++i) {
             var query_results = results[i];
             for (var i2 = 0, l2 = query_results.fql_result_set.length; i2<l2; ++i2) {
                 row = query_results.fql_result_set[i2];
                 console.log(row);
                 // at this point row variable contains individual rows from the link table
                 // with the selected fields
                 console.log(row.owner, row.title); // should log something useful
             }
         }
     }
);

文档指出这应该比使用批处理 api 接口更快:

此方法也比使用 batch.run 运行一系列 fql.query 调用具有更好的性能。

在萤火虫中,第一个console.log(results)应该显示类似于此的内容(实际 id 因空间限制而被删除/截断): Firebug 控制台输出结果

于 2012-08-16T06:28:37.957 回答