【问题标题】:java twitter4j are tweet ids uniquejava twitter4j 是唯一的推文 ID
【发布时间】:2013-08-14 02:20:42
【问题描述】:

用 twitter4j 做一些 java 开发,很想知道我什么时候打电话给

Status tweet = blah blah blah.
long tweetID = tweet.getId(); //Is this unique?

我设置了一个 HashSet 来跟踪我已经收到的推文,并且我有一个重复的打印声明。我的印象是 Twitter 使用 64 位长来生成唯一密钥,但我无法找到 twitter4j 推文 ID 和 Twitter 的推文 ID 之间的任何关联。主要问题是:twitter4j 状态推文 ID 是否唯一?

[编辑] 一些详细说明,我有一个 Longs 的 HashSet

HashSet<Long> usedIds = new HashSet<Long>();
//Get new twitter4j Status
if(!usedIds.contains(tweetID)) {
    //this is not a duplicate
    //Place id into set
    usedIds.add(tweetID);
    //do work
} else {
    //This is duplicate and my program is printing stuff
    //From what I've learned this condition should never be met but it is
}

【问题讨论】:

  • 能否包含将推文 ID 添加到 HashSet 的代码?您是否还可以包含任何其他读/写或以其他方式操作 HashSet 的代码?

标签: java twitter unique twitter4j


【解决方案1】:

我相当肯定 twitter4j 的 Status.getId() 返回推文的唯一 ID,由 Twitter 确定。它不是创建自己的 ID。也许您的 HashSet 对密钥空间过于激进,并且您遇到了冲突,但 getId 调用将为您提供 Tweet 的实际 ID。

【讨论】:

  • 您能否详细说明什么是“积极的”密钥空间处理?
  • 你如何实例化你正在使用的 HashSet?我刚刚查看了 Twitter4J 源——它从 Twitter API 的 HTTP 响应中的 JSON 中提取 ID。 github.com/yusuke/twitter4j/blob/…
  • 私有 HashSet usedIds = new HashSet();当我收到一条新推文时,我会检查 usedIds.contains(tweet.getId())
猜你喜欢
  • 2012-11-19
  • 1970-01-01
  • 1970-01-01
  • 2017-10-29
  • 1970-01-01
  • 1970-01-01
  • 2015-12-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多