3
以下是我的代碼。我的問題是如何獲得另一個帳戶的用戶時間表? (比如像att這樣的公共賬戶)。我有我的用戶密鑰,祕密,訪問令牌,訪問密碼,這些密碼都在我的Twitter帳戶下注冊。請幫幫我。非常感謝你。如何使用twitter4j獲取用戶時間線
import twitter4j.Status;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import twitter4j.conf.ConfigurationBuilder;
import java.util.List;
/**
* @author Yusuke Yamamoto - yusuke at mac.com
* @since Twitter4J 2.1.7
*/
public class GetUserTimeline {
/**
* Usage: java twitter4j.examples.timeline.GetUserTimeline
*
* @param args String[]
*/
public static void main(String[] args) {
// gets Twitter instance with default credentials
Twitter twitter = new TwitterFactory().getInstance();
try {
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey("***")
.setOAuthConsumerSecret("***")
.setOAuthAccessToken("***")
.setOAuthAccessTokenSecret("***");
TwitterFactory tf = new TwitterFactory(cb.build());
Twitter twitter1 = tf.getInstance();
List<Status> statuses;
String user;
if (args.length == 1) {
user = args[0];
statuses = twitter1.getUserTimeline("ATT");
} else {
user = twitter1.verifyCredentials().getScreenName();
statuses = twitter1.getUserTimeline();
}
System.out.println("Showing @" + user + "'s user timeline.");
for (Status status : statuses) {
System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText());
}
} catch (TwitterException te) {
te.printStackTrace();
System.out.println("Failed to get timeline: " + te.getMessage());
System.exit(-1);
}
}
}
你是如何調用'GetUserTimeline'和你得到的任何錯誤/輸出? – Jonathan
您的代碼似乎正確。你有任何錯誤? – Jhanvi