所以我正在尝试制作一个机器人,我试图看看在我尝试转发之前是否有转推的推文。问题是我似乎无法找到办法。我已经尝试了很多方法,如下所示,但我无法弄清楚。我检查过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
答案 0 :(得分:0)
我认为使用status.getRetweetCount()
这个返回总转推号码是推文,如果等于零则不转发但是大于零转发
并检查自己被转发的是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()