Facebook Open Graph API:获取分页用户的新闻提要时参数限制的奇怪行为 [英] Facebook Open Graph API: weird behavior of parameter limit while getting a paginated user's news feed

查看:26
本文介绍了Facebook Open Graph API:获取分页用户的新闻提要时参数限制的奇怪行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 JAVA 编写了一个小脚本,它在查询 用四个不同的值(10、100、1000 和 10000)测试参数 limit>使用开放图谱 APIRestFB 客户端的 Facebook 用户新闻提要>.正如你将看到的,它有一个奇怪的行为......

场景:

public static void main(String[] args) {//变量DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");FacebookClient 客户端 = 新的 DefaultFacebookClient(accessToken);连接<帖子>家;列表<帖子>帖子列表;地图<字符串,帖子>邮政地图;国际我;//测试限制String[] 限制 = {"10", "100", "1000", "10000"};对于(字符串限制:限制){//初始化列表和映射(查找重复的帖子)postList = new LinkedList();postMap = new LinkedHashMap();//获取新闻提要home = client.fetchConnection(id + "/home", Post.class, Parameter.with("limit", limit));//遍历页面我 = 1;for(列表<发布>页面:首页){对于(发布帖子:页面){//存入列表postList.add(post);//存储到地图中(唯一的帖子 ID)postMap.put(post.getId(), post);}我++;}//按创建时间排序帖子Collections.sort(postList, new Comparator() {@覆盖公共 int 比较(发布 post1,发布 post2){返回 post1.getCreatedTime().compareTo(post2.getCreatedTime());}});//日志尝试 {FileWriter out = new FileWriter("log/output.txt", true);out.write("LIMIT:" + limit + "
");out.write("	PAGES:" + (i - 1) + "
");out.write("	LIST SIZE:" + postList.size() + "
");out.write("	MAP SIZE:" + postMap.size() + "
");out.write("	OLDER POST:" + dateFormat.format(postList.get(0).getCreatedTime()) + "
");out.write("	YOUGNER POST:" + dateFormat.format(postList.get(postList.size() - 1).getCreatedTime()) + "
");关闭();} catch (IOException e) {抛出新的运行时异常(e);}}}

输出:

限制:10页数:7列表大小:56地图大小:56旧帖子:2009-03-22 14:58:03青年发帖:2012-05-11 15:48:49限制:100页数:3列表大小:174地图大小:172旧帖子:2012-01-12 23:01:34青年发帖:2012-05-11 15:48:49限制:1000页数:2列表大小:294地图大小:292旧帖子:2009-03-22 14:58:03青年发帖:2012-05-11 15:48:49限制:10000页数:2列表大小:294地图大小:292旧帖子:2009-03-22 14:58:03青年发帖:2012-05-11 15:48:49

解释和问题:

  1. 显然,您无法获取用户自创建帐户以来在其新闻提要中发布的所有帖子.限额有限制吗?

  2. limit 为 100、1000 和 10000,我每次必须在整个返回的新闻提要中两个重复的帖子(174 - 172 =194 - 192).为什么?我从来没有在我的个人新闻提要中看到过两次相同的帖子...

  3. limit 为(且仅)为 100,我得到的较旧帖子是在 2012 年创建的,同时 limit 的其他值使检索 2009 年创建的帖子的查询.我可以理解使用上限 limit(1000 或 10000),查询会检索较旧的帖子.但是为什么 limit 为 10 会使查询检索较旧的帖子,而不是由 100 限制的查询?

  4. 最后但并非最不重要的一点:我收到的帖子数量不一样.显然,limit 越高,检索到的帖子数量就越多.我首先想到的是,较小的 limit 的唯一结果是页数上限(尽管如此),但检索到的帖子数量不会改变.但确实如此.为什么?也就是说,帖子数量似乎在 limit 100 和 1000 之间收敛,因为帖子数量与 limit 1000 和 limit 相同 为 10000.

PS:为查询指定 since 和/或 until 参数不会改变任何东西.

欢迎任何回答/评论:)

干杯.

这是我最好的

此外,对于特定表的结果数也有限制.您可以在相应的 fql 表中获取有关它们的详细信息.

对于流表(用于帖子/提要的表),

<块引用>

流表的每次查询仅限于前30天或50 个帖子,以较大者为准,但您可以使用特定时间字段,例如 created_time 以及 FQL 运算符(例如 < 或 >)检索更广泛的帖子.

参考:Fql 流表

也看这里:Facebook FQL 流限制?

I've written a little script in JAVA, that tests the parameter limit with four different values (10, 100, 1000 and 10000) when querying a user's news feed of Facebook using the Open Graph API and the RestFB client. As you'll see, it has a strange behavior...

Scenario:

public static void main(String[] args) {

    // vars
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    FacebookClient client = new DefaultFacebookClient(accessToken);
    Connection<Post> home;
    List<Post> postList;
    Map<String, Post> postMap;
    int i;

    // limits to test
    String[] limits = {"10", "100", "1000", "10000"};
    for (String limit : limits) {

        // init list and map (looking for duplicate posts)
        postList = new LinkedList<Post>();
        postMap = new LinkedHashMap<String, Post>();
        // get news feed
        home = client.fetchConnection(id + "/home", Post.class, Parameter.with("limit", limit));

        // going through pages
        i = 1;
        for (List<Post> page : home) {
            for (Post post : page) {
                // store into list
                postList.add(post);
                // store into map (unique post id)
                postMap.put(post.getId(), post);
            }
            i++;
        }

        // sort posts by created time
        Collections.sort(postList, new Comparator<Post>() {
            @Override
            public int compare(Post post1, Post post2) {
                return post1.getCreatedTime().compareTo(post2.getCreatedTime());
            }
        });

        // log
        try {
            FileWriter out = new FileWriter("log/output.txt", true);
            out.write("LIMIT: " + limit + "
");
            out.write("	PAGES: " + (i - 1) + "
");
            out.write("	LIST SIZE: " + postList.size() + "
");
            out.write("	MAP SIZE: " + postMap.size() + "
");
            out.write("	OLDER POST: " + dateFormat.format(postList.get(0).getCreatedTime()) + "
");
            out.write("	YOUGNER POST: " + dateFormat.format(postList.get(postList.size() - 1).getCreatedTime()) + "
");
            out.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }

}

Output:

LIMIT: 10
    PAGES: 7
    LIST SIZE: 56
    MAP SIZE: 56
    OLDER POST: 2009-03-22 14:58:03
    YOUGNER POST: 2012-05-11 15:48:49
LIMIT: 100
    PAGES: 3
    LIST SIZE: 174
    MAP SIZE: 172
    OLDER POST: 2012-01-12 23:01:34
    YOUGNER POST: 2012-05-11 15:48:49
LIMIT: 1000
    PAGES: 2
    LIST SIZE: 294
    MAP SIZE: 292
    OLDER POST: 2009-03-22 14:58:03
    YOUGNER POST: 2012-05-11 15:48:49
LIMIT: 10000
    PAGES: 2
    LIST SIZE: 294
    MAP SIZE: 292
    OLDER POST: 2009-03-22 14:58:03
    YOUGNER POST: 2012-05-11 15:48:49

Interpretations and questions:

  1. Obviously, you can't get all the posts a user has had on his news feed since his account was created. Is limit limited?

  2. With a limit of 100, 1000 and 10000, I must have had each time two duplicated posts within the whole returned news feed (174 - 172 = 194 - 192). Why? I never saw the same post twice on my personal news feed...

  3. With (and only with) a limit of 100, the older post I get was created during the year 2012, meanwhile the other values of limit make the query retrieving a post that was created during the year 2009. I can understand that with an upper limit (1000 or 10000), the query retrieves older posts. But why does a limit of 10 make the query retrieving an older post than a query limited by 100?

  4. Last but not least point: I'm not getting the same number of posts. Obviously, the more the limit is high, the more the number of retrieved posts is high. What I thought first, is that the only consequence of a smaller limit was an upper number of pages (which is the case though), but that the number of retrieved posts would not change. But it does. Why? That said, the number of posts seems to converge between a limit of 100 and 1000, because the number of posts is identical with a limit of 1000 and a limit of 10000.

PS: specifying a since and/or a until parameter to the query doesn't change anything.

Any answer/comment is welcome :)

Cheers.

Edit:

This is my best recall:

LIMIT: 200
    PAGES: 3
    LIST SIZE: 391
    MAP SIZE: 389
    OLDER POST: 2012-01-27 14:17:16
    YOUGNER POST: 2012-05-11 16:52:38

Why 200? Is it specified anywhere in the documentation?

解决方案

Its not in documentation but personally I have tested following for my project.

Facebook limit is limited to 500 posts. No matter you put a limit higher than 500 it will fetch only 500 results max. Try with 500 (or more), you will get maximum posts.

You wont get 500 posts every time but will get above 490 posts in general. Some posts get filtered by various reasons (like privacy, blocked user, not suitable for specific region and other things)

This answers your 1st and 4th quetion.

For question no. 2 , I do not work in java, so I cant say if there's a prob in your code/logic or what your code is doing.

For question no. 3 , God help facebook !

Edit

For 4th problem, you may be hitting the queries/hour limit of graph api (facebook uses it to prevent spamming, you cant query apis frequently in quick succession)

Also,

this is why, you do not get all results returned by facebook.

(if you specified a limit of "5" but the five posts returned are not visible to the viewer, you will get an empty result set.)

In addition to the limits mentioned in the documentation for each of the tables and connections listed above, it is helpful to know that the maximum number of results we will fetch before running the visibility checks is 5,000.

Reference: Paging with graph api and fql

Also, there is a limit on no of results for a particular table. You can get a detail about them on respective fql tables.

For stream table (the one for posts/feed),

Each query of the stream table is limited to the previous 30 days or 50 posts, whichever is greater, however you can use time-specific fields such as created_time along with FQL operators (such as < or >) to retrieve a much greater range of posts.

Reference: Fql stream table

Look here too: Facebook FQL stream limit?

这篇关于Facebook Open Graph API:获取分页用户的新闻提要时参数限制的奇怪行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆