Search in sources :

Example 1 with OAuthAuthorization

use of twitter4j.http.OAuthAuthorization in project AndroidSDK-RecipeBook by gabu.

the class Recipe102 method onResume.

public void onResume() {
    super.onResume();
    // プリファレンスを取得
    SharedPreferences sp = getSharedPreferences(PREF_NAME, MODE_PRIVATE);
    // tokenとtokenSecretを取得
    String token = sp.getString(PREF_KEY_TOKEN, "");
    String tokenSecret = sp.getString(PREF_KEY_TOKEN_SECRET, "");
    // 値がなければAuthアクティビティを起動
    if ("".equals(token) || "".equals(tokenSecret)) {
        Intent intent = new Intent(this, Auth.class);
        startActivity(intent);
    }
    // twitter4jのConfigurationを取得
    Configuration conf = ConfigurationContext.getInstance();
    // AccessTokenを生成
    AccessToken accessToken = new AccessToken(token, tokenSecret);
    // OAuthAuthorizationを生成
    Authorization auth = new OAuthAuthorization(conf, conf.getOAuthConsumerKey(), conf.getOAuthConsumerSecret(), accessToken);
    // OAuthAuthorizationを使ってTwitterインスタンスを生成
    Twitter twitter = new TwitterFactory().getInstance(auth);
    try {
        // とりあえずテストのためTLをログ出力
        ResponseList<Status> statuses = twitter.getHomeTimeline();
        for (Status status : statuses) {
            Log.d(TAG, status.getUser().getName() + ":" + status.getText());
        }
    } catch (TwitterException e) {
        e.printStackTrace();
    }
}
Also used : Authorization(twitter4j.http.Authorization) OAuthAuthorization(twitter4j.http.OAuthAuthorization) Status(twitter4j.Status) Configuration(twitter4j.conf.Configuration) SharedPreferences(android.content.SharedPreferences) AccessToken(twitter4j.http.AccessToken) Twitter(twitter4j.Twitter) Intent(android.content.Intent) TwitterFactory(twitter4j.TwitterFactory) OAuthAuthorization(twitter4j.http.OAuthAuthorization) TwitterException(twitter4j.TwitterException)

Aggregations

Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 Status (twitter4j.Status)1 Twitter (twitter4j.Twitter)1 TwitterException (twitter4j.TwitterException)1 TwitterFactory (twitter4j.TwitterFactory)1 Configuration (twitter4j.conf.Configuration)1 AccessToken (twitter4j.http.AccessToken)1 Authorization (twitter4j.http.Authorization)1 OAuthAuthorization (twitter4j.http.OAuthAuthorization)1