简体   繁体   中英

java twitter4j are tweet ids unique

Doing some java dev with twitter4j and curious to know if when I make a call to

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

I setup a HashSet in order to keep track of tweets I've already received and I have a print statement for duplicates. I was under the impression that Twitter used a 64bit long to generate unique keys but I was unable to find any correlation between the twitter4j tweet id and Twitter's tweet id. Main question is: Are the twitter4j Status tweet ids unique?

[Edit] Some elaboration, I have a HashSet of Longs

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
}

I'm fairly certain the twitter4j's Status.getId() returns the unique ID of the Tweet, as determined by Twitter. It's not creating it's own IDs. Perhaps your HashSet is too aggressive with the key space and you're getting a collision, but the getId call is going to give you the Tweet's actual ID.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM