gpt4 book ai didi

java - 检查推文是否已被转发 - Twitter4j

转载 作者:太空宇宙 更新时间:2023-11-04 12:47:19 24 4
gpt4 key购买 nike

所以我正在尝试制作一个机器人,并且在尝试转发之前尝试查看推文是否已被转发。问题是我似乎找不到办法做到这一点。我尝试了很多方法,如下所示,但我无法弄清楚。我检查了 Stackoverflow 和 Twitter4j 但找不到解决方案

我的代码:

private boolean retweetedAlready(Status status) throws TwitterException {
System.out.println("Status ID: " + status.getId());
System.out.println("Retweeted: " + status.isRetweetedByMe());

List<Status> retweets = twitter.getRetweetsOfMe();
Status tmp;
for(Status s : twitter.getUserTimeline()){
tmp = s.getRetweetedStatus();
System.out.println("ID: " + s.getId());
System.out.println("Equal: " + status.equals(s));
System.out.println("Retweeted Status id: " + tmp.getId());
System.out.println(tmp.getId() + ", " + status.getId() + " - " + (tmp.getId() == status.getId()));
System.out.println(retweets.contains(status));
System.out.println();
if(s.getRetweetedStatus().getId() == status.getId()){
return true;
}
}
return false;
}

输出:

Status ID: 712688409878331392
Retweeted: false
ID: 712688575494688768
Equal: false
Retweeted Status id: 712654036646891520
712654036646891520, 712688409878331392 - false
false

ID: 712688572063752194
Equal: false
Retweeted Status id: 712687766178365441
712687766178365441, 712688409878331392 - false
false

ID: 712688568678875137
Equal: false
Retweeted Status id: 712663978158071810
712663978158071810, 712688409878331392 - false
false

ID: 712364624251846658
Equal: false
Retweeted Status id: 712226571634008065
712226571634008065, 712688409878331392 - false
false

ID: 712364621743661060
Equal: false
Retweeted Status id: 712056778410713088
712056778410713088, 712688409878331392 - false
false

ID: 712361537680310274
Equal: false
Retweeted Status id: 712345290464886784
712345290464886784, 712688409878331392 - false
false

ID: 712361535302180864
Equal: false
Retweeted Status id: 712361382474346497
712361382474346497, 712688409878331392 - false
false

ID: 712361075149246466
Equal: false
Retweeted Status id: 712360810211897344
712360810211897344, 712688409878331392 - false
false

ID: 712361072687239168
Equal: false
Retweeted Status id: 712360816801136641
712360816801136641, 712688409878331392 - false
false

ID: 712361069872877569
Equal: false
Retweeted Status id: 712310621748862978
712310621748862978, 712688409878331392 - false
false

ID: 712361066936799232
Equal: false
Retweeted Status id: 712360862120435712
712360862120435712, 712688409878331392 - false
false

ID: 712361063744929792
Equal: false
Retweeted Status id: 712360922182975490
712360922182975490, 712688409878331392 - false
false

ID: 712360695069872130
Equal: false
Retweeted Status id: 712360559329595392
712360559329595392, 712688409878331392 - false
false

ID: 712360607538946050
Equal: false
Retweeted Status id: 712349483066105856
712349483066105856, 712688409878331392 - false
false

ID: 712359955043635201
Equal: false
Retweeted Status id: 712292676352274433
712292676352274433, 712688409878331392 - false
false

ID: 712359949565870080
Equal: false
Retweeted Status id: 712359728286965765
712359728286965765, 712688409878331392 - false
false

ID: 712359946835333120
Equal: false
Retweeted Status id: 712359289365499904
712359289365499904, 712688409878331392 - false
false

ID: 712359944209764352
Equal: false
Retweeted Status id: 709161338342248448
709161338342248448, 712688409878331392 - false
false

ID: 712359940627816448
Equal: false
Retweeted Status id: 712359805805993985
712359805805993985, 712688409878331392 - false
false

最佳答案

我觉得用status.getRetweetCount()这个返回总转发数就是tweet,如果等于0则不转发,大于0则转发

并检查自己转发的推文是 status.isRetweetedByMe()

   private boolean retweetedAlready(Status status) throws TwitterException {

if(status.isRetweetedByMe() && status.getRetweetCount() > 1 ){

return true; // this twit retweeted by your and others
} else if(status.isRetweetedByMe() && status.getRetweetCount() == 1 )
return true; // this twit only retweeted by your
}else{
return false; // this twit not retweeted by your but mybe others retweeted
}

}

并将 getUserTimeline() 更改为 getHomeTimeline() 以获取推文,isRetweetedByMe() 不适用于 getUserTimeline()

关于java - 检查推文是否已被转发 - Twitter4j,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36184711/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com