static
{
System.setProperty("weibo4j.oauth.consumerKey", Weibo.CONSUMER_KEY);
System.setProperty("weibo4j.oauth.consumerSecret", Weibo.CONSUMER_SECRET);
weibo = new Weibo();
weibo.setToken("25ec2f9cf068b042b4e34155d4c546ff", "0f7135f8815be8df10bab0c0b46cca2f");
}
/**
* @param args
*/
public static void main(String[] args)
{
//showUser();
//updateStatus();
getFriendsTimeline();
}
/**
* 获取用户最新的20条微博
*/
public static void getFriendsTimeline()
{
try {
//获取前20条关注用户的微博信息
List<Status> statuses = weibo.getFriendsTimeline();
for (Status status : statuses) {
System.out.println(status.getUser().getName() + ":" +
status.getText());
}
} catch (WeiboException e) {
e.printStackTrace();
}
}
/**
* 获取当前登录用户信息
*/
public static void showUser()
{
try {
User user=weibo.showUser(USER_ID);
System.out.println(user.getId());
System.out.println(user.getName());
System.out.println(user.getFriendsCount());
System.out.println(user.getProfileImageURL().toString());
} catch (WeiboException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void updateStatus()
{
try {
Status status =weibo.updateStatus("hehe,我来啦。Welcome me");
System.out.println(status.getText());
System.out.println(status.getUser().getName());
} catch (WeiboException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
{
System.setProperty("weibo4j.oauth.consumerKey", Weibo.CONSUMER_KEY);
System.setProperty("weibo4j.oauth.consumerSecret", Weibo.CONSUMER_SECRET);
weibo = new Weibo();
weibo.setToken("25ec2f9cf068b042b4e34155d4c546ff", "0f7135f8815be8df10bab0c0b46cca2f");
}
/**
* @param args
*/
public static void main(String[] args)
{
//showUser();
//updateStatus();
getFriendsTimeline();
}
/**
* 获取用户最新的20条微博
*/
public static void getFriendsTimeline()
{
try {
//获取前20条关注用户的微博信息
List<Status> statuses = weibo.getFriendsTimeline();
for (Status status : statuses) {
System.out.println(status.getUser().getName() + ":" +
status.getText());
}
} catch (WeiboException e) {
e.printStackTrace();
}
}
/**
* 获取当前登录用户信息
*/
public static void showUser()
{
try {
User user=weibo.showUser(USER_ID);
System.out.println(user.getId());
System.out.println(user.getName());
System.out.println(user.getFriendsCount());
System.out.println(user.getProfileImageURL().toString());
} catch (WeiboException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void updateStatus()
{
try {
Status status =weibo.updateStatus("hehe,我来啦。Welcome me");
System.out.println(status.getText());
System.out.println(status.getUser().getName());
} catch (WeiboException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
方法showUser(),getFriendsTimeline(),还有updateStatus()中有重复的代码段,可以将其提出在公共区域。