public void datamining_Tweets() { // TODO Auto-generated method stub for (int i = 0; i < Mining.WeiboNumberMax; i++) { Weibo weibo = Mining.initiation.getWeibo(i); int RateLimitRemain = Mining.RateLimitMax; loop: for (int j = Mining.NextTweetID; j < Mining.UniqueUserIDList.size(); j++) { try { ArrayList<Status> tweets = new ArrayList<Status>(); ArrayList<Long> TweetsID = new ArrayList<Long>(); ArrayList<Long> TweetsTime = new ArrayList<Long>(); ArrayList<Status> reposts = new ArrayList<Status>(); ArrayList<Long> RepostsID = new ArrayList<Long>(); ArrayList<Long> RepostsTime = new ArrayList<Long>(); ArrayList<Long> RepostsUserID = new ArrayList<Long>(); System.out.println("WeiboAccount: " + i); if (RateLimitRemain > 0) { System.out.println(System.currentTimeMillis()); tweets = getUserTimeline(weibo, String.valueOf(Mining.UniqueUserIDList.get(j).longValue())); reposts = getUserReposts(weibo, String.valueOf(Mining.UniqueUserIDList.get(j).longValue())); System.out.println(System.currentTimeMillis()); for (Status tweet : tweets) { TweetsID.add(tweet.getId()); TweetsTime.add(tweet.getCreatedAt().getTime()); } System.out.println(System.currentTimeMillis()); for (Status repost : reposts) { RepostsID.add(repost.getId()); RepostsTime.add(repost.getCreatedAt().getTime()); RepostsUserID.add(repost.getUser().getId()); } System.out.println(System.currentTimeMillis()); } Mining.NextTweetID++; System.out.println("Mining.NextTweetID: " + Mining.NextTweetID); Mining.exportdata.ExportNextUniqueIDTweet(Mining.processing, Mining.NextTweetID); Mining.exportdata.ExportUserTweetsID( Mining.processing, Mining.UniqueUserIDList.get(j), TweetsID, TweetsTime, RepostsID, RepostsUserID, RepostsTime); // System.exit(0); } catch (WeiboException e) { System.out.println("RateLimitRemain: " + RateLimitRemain); e.printStackTrace(); break loop; } } } }
public static boolean getComments() throws ClassNotFoundException, SQLException, InterruptedException { boolean isDone = true; System.out.println(" Will connect to the database and get status......."); Connection conComments = PublicMethods.getConnection(); System.out.println( " Okay the connnection to mysql has been established..we are going to select id from status....."); java.sql.Statement stmt = conComments.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rset = stmt.executeQuery("select id, commentCounts from status where isDone = false limit 100"); int pageNum = 1; int commentCounts = 0; long statusId = (long) 0; while (rset.next()) { isDone = false; statusId = rset.getLong(1); commentCounts = rset.getInt(2); System.out.println("commentCounts: " + commentCounts); // Thread.sleep(2000); if (commentCounts == 0) { PublicMethods.UpdateStatusComments(conComments, statusId); // continue; } else { try { Paging pag = new Paging(); pag.setCount(100); pageNum = 1; do { pag.setPage(pageNum); List<Comment> comments = PublicMethods.weibo.getComments(statusId + "", pag); // List<Comment> comments = PublicMethods.weibo.getComments("3343531616094195",pag); pageNum++; if (comments.isEmpty()) { // Thread.sleep(4700); break; } else { for (Comment comment : comments) { PublicMethods.InsertCommentsSql(conComments, comment, statusId); commentCounts--; } if (commentCounts <= 100) { break; } } // Thread.sleep(5700); } while (true); PublicMethods.UpdateStatusComments(conComments, statusId); } catch (WeiboException e) { e.printStackTrace(); } } } conComments.close(); return isDone; }
/** * @param token request token * @param tokenSecret request token secret * @return access token * @throws WeiboException * @since Weibo4J 1.2.0 */ public AccessToken getOAuthAccessToken(String token, String tokenSecret) throws WeiboException { try { this.oauthToken = new OAuthToken(token, tokenSecret) {}; this.oauthToken = new AccessToken(httpRequest(accessTokenURL, new PostParameter[0], true)); } catch (WeiboException te) { throw new WeiboException( "The user has not given access to the account.", te, te.getStatusCode()); } return (AccessToken) this.oauthToken; }
/** * 是否关注某用户 * * @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 { // args[2]:自己的id;args[3]:关注对象的id boolean bool = getWeibo(true, args).existsFriendship(args[2], args[3]); // args[2]:关注用户的id System.out.println(bool); } catch (WeiboException e) { e.printStackTrace(); } }
/** * 添加收藏 * * @param args args[0]和args[1]为通过GetToken.java获取到的accesstoken和accesstoken secret * args[2]为将要收藏的statusId */ public static void main(String[] args) { System.setProperty("weibo4j.oauth.consumerKey", Weibo.CONSUMER_KEY); System.setProperty("weibo4j.oauth.consumerSecret", Weibo.CONSUMER_SECRET); try { Weibo weibo = new Weibo(); weibo.setToken(args[0], args[1]); Status status = weibo.createFavorite(Long.parseLong(args[2])); System.out.println(status.toString()); } catch (WeiboException e) { e.printStackTrace(); } }
public int GetCurrentCountInfo() { try { RateLimitStatus data = am.getAccountRateLimitStatus(); return data.getRemainingIpHits(); } catch (WeiboException e) { // TODO Auto-generated catch block e.printStackTrace(); } return 0; // TODO Auto-generated method stub }
public UserData GetUserData(String userName) { User userdata = null; try { userdata = um.showUserByScreenName(userName); } catch (WeiboException e) { // TODO Auto-generated catch block e.printStackTrace(); } return DataConverter.ConvertFrom(userdata); // TODO Auto-generated method stub // return null; }
public List<StatusData> GetRepostStatus(String statusId, int mount) { List<Status> status; try { status = tm.getRepostTimeline(statusId, mount, 1).getStatuses(); List<StatusData> statusDatas = new ArrayList<StatusData>() {}; for (Status status2 : status) { statusDatas.add(DataConverter.ConvertFrom(status2)); } return statusDatas; } catch (WeiboException e) { // TODO Auto-generated catch block e.printStackTrace(); } return new ArrayList<StatusData>(); }
/** * @param token request token * @return access token * @throws WeiboException * @since Weibo4J 1.2.0 */ public AccessToken getOAuthAccessToken(RequestToken token, String pin) throws WeiboException { try { this.oauthToken = token; this.oauthToken = new AccessToken( httpRequest( accessTokenURL, new PostParameter[] {new PostParameter("oauth_verifier", pin)}, true)); } catch (WeiboException te) { throw new WeiboException( "The user has not given access to the account.", te, te.getStatusCode()); } return (AccessToken) this.oauthToken; }
/** * 返回用户关注对象列表,并返回最新微博文章。 * * @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 { Weibo weibo = new Weibo(); weibo.setToken(args[0], args[1]); int cursor = 5; // 采用cursor参数处理翻页 List<User> list = weibo.getFollowersStatuses("1377583044", cursor); for (User user : list) { System.out.println(user.toString()); } } catch (WeiboException e) { e.printStackTrace(); } }
public List<StatusData> GetUserStatus(String people, int mount) { // TODO Auto-generated method stub try { List<Status> statuss = tm.getUserTimelineByName(people, mount, 1, 1).getStatuses(); List<StatusData> statusDatas = new ArrayList<StatusData>(); for (Status status : statuss) { statusDatas.add(DataConverter.ConvertFrom(status)); } return statusDatas; } catch (WeiboException e) { // TODO Auto-generated catch block e.printStackTrace(); } return new ArrayList<StatusData>(); }
public static Status derByJSONLib_intern(JSONArray arr) { Status ret = null; try { if (arr.size() >= 1) { ret = new Status(arr.getJSONObject(0)); if (arr.size() == 2) { Status rt = new Status(arr.getJSONObject(1)); ret.setRetweetedStatus(rt); } } } catch (JSONException | WeiboException e) { e.printStackTrace(); } catch (weibo4j.WeiboException e) { e.printStackTrace(); } return ret; }
/** @param args */ public static void main(String[] args) { // TODO Auto-generated method stub System.setProperty("weibo4j.oauth.consumerKey", Weibo.CONSUMER_KEY); System.setProperty("weibo4j.oauth.consumerSecret", Weibo.CONSUMER_SECRET); Paging paging = new Paging(); paging.setCount(20); paging.setPage(1); try { Weibo weibo = new Weibo(); weibo.setToken(args[0], args[1]); List<Trends> trendsWeekly = weibo.getTrendsWeekly(0); System.out.println("=======按周返回热门话题======="); System.out.println(trendsWeekly); } catch (WeiboException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
public List<Long> GetRelationIDs(RelationType relationType, String searchinfo, int mount) { switch (relationType) { case Friend: try { return Translate(fm.getFriendsIdsByUid(searchinfo, mount, 0)); } catch (WeiboException e1) { // TODO Auto-generated catch block e1.printStackTrace(); return new ArrayList<Long>(); } case FriendsOnBilateral: try { return Translate(fm.getFriendsBilateralIds(searchinfo, mount, 0)); } catch (WeiboException e) { // TODO Auto-generated catch block e.printStackTrace(); return new ArrayList<Long>(); } case Follows: try { return Translate(fm.getFollowersIdsById(searchinfo, mount, 0)); } catch (WeiboException e) { // TODO Auto-generated catch block e.printStackTrace(); } break; } return new ArrayList<Long>(); }