Skip to content

Instantly share code, notes, and snippets.

@yusuke
Created November 29, 2010 13:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yusuke/719924 to your computer and use it in GitHub Desktop.
Save yusuke/719924 to your computer and use it in GitHub Desktop.
/*
Copyright (c) 2010-2010, Yusuke Yamamoto
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Yusuke Yamamoto nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY Yusuke Yamamoto ``AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL Yusuke Yamamoto BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import twitter4j.PagableResponseList;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import twitter4j.User;
import twitter4j.conf.Configuration;
import twitter4j.conf.ConfigurationBuilder;
/**
* @author Yusuke Yamamoto - yusuke at mac.com
*/
public class CursorTest {
public static void main(String[] args) throws TwitterException {
Configuration conf = new ConfigurationBuilder().setDebugEnabled(false).build();
Twitter twitter = new TwitterFactory(conf).getInstance();
long cursor = -1;
System.out.println("フォロー数:"+twitter.verifyCredentials().getFriendsCount());
PagableResponseList<User> users;
// 二度呼び出してもカーソルが同じ値かどうか確認
users = twitter.getFriendsStatuses(cursor);
cursor = users.getNextCursor();
System.out.println("一回目(1ページ目) next cursor:" + cursor);
System.out.println("一回目(1ページ目) previous cursor:" + users.getPreviousCursor());
System.out.println(users.size() + "人分取得");
// カーソルを初期化して1ページ目を再度読み込み
cursor = -1;
users = twitter.getFriendsStatuses(cursor);
cursor = users.getNextCursor();
System.out.println("二回目(1ページ目) next cursor:" + cursor);
System.out.println("二回目(1ページ目) previous cursor:" + users.getPreviousCursor());
System.out.println(users.size() + "人分取得");
// オバマ大統領をフォロー
twitter.createFriendship("BarackObama");
System.out.println("フォロー数:"+twitter.verifyCredentials().getFriendsCount());
// フォロー後に2ページ目を取得できるか?
users = twitter.getFriendsStatuses(cursor);
System.out.println("三回目(2ページ目) next cursor:" + users.getNextCursor());
System.out.println("三回目(2ページ目) previous cursor:" + users.getPreviousCursor());
System.out.println(users.size() + "人分取得");
// オバマ大統領のフォローを解除
twitter.destroyFriendship("BarackObama");
System.out.println("フォロー数:"+twitter.verifyCredentials().getFriendsCount());
users = twitter.getFriendsStatuses(cursor);
System.out.println("四回目(2ページ目) next cursor:" + users.getNextCursor());
System.out.println("四回目(2ページ目) previous cursor:" + users.getPreviousCursor());
System.out.println(users.size() + "人分取得");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment