【IT168 技术】你想将Twitter集成到你的程序中吗?创建一个很酷的程序吧。使用JTwitter.库可以实现这个奇趣的想法。
以下是示例程序:
package de.vogella.twitter.test;
import java.util.List;
import winterwell.jtwitter.Twitter;
import winterwell.jtwitter.Twitter.User;
public class TwitterTest {
private static final String user ="your-user";
private static final String pw ="your-password";
public static void main(String[] args) {
// Make a Twitter object
Twitter twitter = new TwitterFactory().getInstance(user,pw);
// Print Lars Vogel status
System.out.println(twitter.getStatus("vogella"));
// Set my status
twitter.setStatus("@vogella messing with Twitter in Java");
List followers = twitter.getFollowers();
for (User user : followers) {
System.out.println(user.getName());
}
}
}
import java.util.List;
import winterwell.jtwitter.Twitter;
import winterwell.jtwitter.Twitter.User;
public class TwitterTest {
private static final String user ="your-user";
private static final String pw ="your-password";
public static void main(String[] args) {
// Make a Twitter object
Twitter twitter = new TwitterFactory().getInstance(user,pw);
// Print Lars Vogel status
System.out.println(twitter.getStatus("vogella"));
// Set my status
twitter.setStatus("@vogella messing with Twitter in Java");
List followers = twitter.getFollowers();
for (User user : followers) {
System.out.println(user.getName());
}
}
}
推荐另一个库Twitter4J,你也可以尝试用它来实现。