Package weibo4j.examples.timeline

Source Code of weibo4j.examples.timeline.GetUserTimeline

/**
*
*/
package weibo4j.examples.timeline;

import java.util.List;

import weibo4j.Paging;
import weibo4j.Status;
import weibo4j.Weibo;
import weibo4j.WeiboException;

/**
* @author hezhou
*
*/
public class GetUserTimeline {

  /**
   * 获取用户发布的微博信息列表
   * @param args
   */
  public static void main(String[] args) {
    System.setProperty("weibo4j.oauth.consumerKey", Weibo.CONSUMER_KEY);
      System.setProperty("weibo4j.oauth.consumerSecret", Weibo.CONSUMER_SECRET);
    try {
      //获取24小时内前20条用户的微博信息;args[2]:用户ID
      List<Status> statuses = getWeibo(false,args).getUserTimeline(args[2],new Paging(1,200));
      for (Status status : statuses) {
              System.out.println(status.getUser().getName() + ":" +
                                 status.getText());
          }
    } catch (WeiboException e) {
      e.printStackTrace();
    }
  }
 
  private static Weibo getWeibo(boolean isOauth,String[] args) {
    Weibo weibo = new Weibo();
    if(isOauth) {//oauth验证方式 args[0]:访问的token;args[1]:访问的密匙
      weibo.setToken(args[0], args[1]);
    }else {//用户登录方式
        weibo.setUserId(args[0]);//用户名/ID
        weibo.setPassword(args[1]);//密码
    }
    return weibo;
  }

}
TOP

Related Classes of weibo4j.examples.timeline.GetUserTimeline

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.