当我有推文 ID 和用户 ID 时,如何获取推文?我有一个包含以下行的文件:
userID tweetID
我想我应该去:
Query query = new Query("huh ?");
QueryResult result = twitter.search(query);
List<Status> tweets = result.getTweets();
但我不知道如何拼写query
谢谢
当我有推文 ID 和用户 ID 时,如何获取推文?我有一个包含以下行的文件:
userID tweetID
我想我应该去:
Query query = new Query("huh ?");
QueryResult result = twitter.search(query);
List<Status> tweets = result.getTweets();
但我不知道如何拼写query
谢谢
好吧,这不是搜索电话。这条推文显然被调用Status
了,通过 ID 检索一条的代码是:
final Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_KEY_SECRET);
AccessToken accessToken = new AccessToken(TWITTER_TOKEN,
TWITTER_TOKEN_SECRET);
twitter.setOAuthAccessToken(accessToken);
try {
Status status = twitter.showStatus(Long.parseLong(tweetID));
if (status == null) { //
// don't know if needed - T4J docs are very bad
} else {
System.out.println("@" + status.getUser().getScreenName()
+ " - " + status.getText());
}
} catch (TwitterException e) {
System.err.print("Failed to search tweets: " + e.getMessage());
// e.printStackTrace();
// DON'T KNOW IF THIS IS THROWN WHEN ID IS INVALID
}
接受的答案不再有效。根据this page中的答案,代码应更改为以下内容:
String consumerKey = xxxxxxx,
consumerSecret = xxxxxxx,
twitterAccessToken = xxxxxxx,
twitterAccessTokenSecret = xxxxxxx,
Tweet_ID = xxxxxxx;
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.setOAuthConsumerKey(consumerKey);
builder.setOAuthConsumerSecret(consumerSecret);
Configuration configuration = builder.build();
TwitterFactory factory = new TwitterFactory(configuration);
final Twitter twitter = factory.getInstance();
//twitter.setOAuthConsumer(consumerKey, consumerSecret);
AccessToken accessToken = new AccessToken(twitterAccessToken, twitterAccessTokenSecret);
twitter.setOAuthAccessToken(accessToken);
try {
Status status = twitter.showStatus(Long.parseLong(Tweet_ID));
if (status == null) { //
// don't know if needed - T4J docs are very bad
} else {
System.out.println("@" + status.getUser().getScreenName()
+ " - " + status.getText());
}
} catch (
TwitterException e) {
System.err.print("Failed to search tweets: " + e.getMessage());
// e.printStackTrace();
// DON'T KNOW IF THIS IS THROWN WHEN ID IS INVALID
}