Android Open Source - twittah Twitter Client






From Project

Back to project page twittah.

License

The source code is released under:

MIT License

If you think the Android project twittah listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.codepath.wangela.apps.twittah.helpers;
/*from   ww  w .  j av  a2  s  . c o m*/
import org.json.JSONObject;
import org.scribe.builder.api.Api;
import org.scribe.builder.api.TwitterApi;

import android.content.Context;
import android.util.Log;

import com.codepath.oauth.OAuthBaseClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.JsonHttpResponseHandler;
import com.loopj.android.http.RequestParams;

/*
 * 
 * This is the object responsible for communicating with a REST API. 
 * Specify the constants below to change the API being communicated with.
 * See a full list of supported API classes: 
 *   https://github.com/fernandezpablo85/scribe-java/tree/master/src/main/java/org/scribe/builder/api
 * Key and Secret are provided by the developer site for the given API i.e dev.twitter.com
 * Add methods for each relevant endpoint in the API.
 * 
 * NOTE: You may want to rename this object based on the service i.e TwitterClient or FlickrClient
 * 
 */
public class TwitterClient extends OAuthBaseClient {
  public static final Class<? extends Api> REST_API_CLASS = TwitterApi.class; // Change
  // this
  public static final String REST_URL = "https://api.twitter.com/1.1"; // Change
  // this,
  // base
  // API
  // URL
  public static final String REST_CONSUMER_KEY = "WN3SbP10m3qK1prPF14gd9t3j"; // Change
  // this
  public static final String REST_CONSUMER_SECRET = "7J24pQ6iQuvvfJb8ITZJwvf8DypaIjuW8m1jCKTcVspjCH2ybC"; // Change
  // this
  public static final String REST_CALLBACK_URL = "oauth://cptwittahtweets"; // Change

  // this
  // (here
  // and
  // in
  // manifest)
  // private
  // String
  // userScreenname
  // =
  // "";

  public TwitterClient(Context context) {
    super(context, REST_API_CLASS, REST_URL, REST_CONSUMER_KEY,
        REST_CONSUMER_SECRET, REST_CALLBACK_URL);
  }

  // public void getTimeline(String code, String timelineType, String sinceId,
  // String maxId, AsyncHttpResponseHandler handler) {
  // RequestParams params = new RequestParams();
  // String apiUrl = "";
  // if (timelineType == "HOME") {
  // apiUrl = getApiUrl("statuses/home_timeline.json");
  // } else if (code == "MENTIONS") {
  // apiUrl = getApiUrl("statuses/mentions_timeline.json");
  // } else if (code == "USER") {
  // apiUrl = getApiUrl("statuses/user_timeline.json");
  // params.put("user_id", userScreenname);
  // }
  // if (code == "LOAD") { // initial load
  // params = null;
  // } else if (code == "MORE") { // load more / pagination
  // params.put("max_id", maxId);
  // } else if (code == "REFRESH") { // refresh timeline
  // params.put("since_id", sinceId);
  // } else {
  // Log.d("ERROR", "code has invalid value of " + code);
  // }
  // client.get(apiUrl, params, handler);
  // }

  public void getHomeTimeline(String code, String sinceId, String maxId,
      AsyncHttpResponseHandler handler) {
    String apiUrl = getApiUrl("statuses/home_timeline.json");
    RequestParams params = new RequestParams();
    if (code == "LOAD") { // initial load
      params = null;
    } else if (code == "MORE") { // load more / pagination
      params.put("max_id", maxId);
    } else if (code == "REFRESH") { // refresh timeline
      params.put("since_id", sinceId);
    } else {
      Log.d("ERROR", "code has invalid value of " + code);
    }
    client.get(apiUrl, params, handler);
  }

  public void getMentionsTimeline(String code, String sinceId, String maxId,
      AsyncHttpResponseHandler handler) {
    String apiUrl = getApiUrl("statuses/mentions_timeline.json");
    RequestParams params = new RequestParams();
    if (code == "LOAD") { // initial load
      params = null;
    } else if (code == "MORE") { // load more / pagination
      params.put("max_id", maxId);
    } else if (code == "REFRESH") { // refresh timeline
      params.put("since_id", sinceId);
    } else {
      Log.d("ERROR", "code has invalid value of " + code);
    }
    client.get(apiUrl, params, handler);
  }

  public void getUserTimeline(String screenname, String code, String sinceId,
      String maxId, AsyncHttpResponseHandler handler) {
    String apiUrl = getApiUrl("statuses/user_timeline.json");
    RequestParams params = new RequestParams();
    params.put("screen_name", screenname);
    if (code == "LOAD") { // initial load
      params = null;
    } else if (code == "MORE") { // load more / pagination
      params.put("max_id", maxId);
    } else if (code == "REFRESH") { // refresh timeline
      params.put("since_id", sinceId);
    } else {
      Log.d("ERROR", "code has invalid value of " + code);
    }
    client.get(apiUrl, params, handler);
  }


  public void getMyProfile(AsyncHttpResponseHandler handler) {
    String apiUrl = getApiUrl("account/verify_credentials.json");
    client.get(apiUrl, handler);
  }

  public void getUserProfile(String screenname,
      AsyncHttpResponseHandler handler) {
    String apiUrl = getApiUrl("users/lookup.json"); // Returns ARRAY not object
    RequestParams params = new RequestParams();
    params.put("screen_name", screenname);
    client.get(apiUrl, params, handler);
  }

  public void postTweet(String status, RequestParams params,
      AsyncHttpResponseHandler handler) {
    String apiUrl = getApiUrl("statuses/update.json");
    params.put("status", status);
    client.post(apiUrl, params, handler);
  }

}




Java Source Code List

com.codepath.wangela.apps.twittah.activities.ComposeActivity.java
com.codepath.wangela.apps.twittah.activities.LoginActivity.java
com.codepath.wangela.apps.twittah.activities.ProfileActivity.java
com.codepath.wangela.apps.twittah.activities.TimelineActivity.java
com.codepath.wangela.apps.twittah.activities.TweetDetailActivity.java
com.codepath.wangela.apps.twittah.activities.TwitterApplication.java
com.codepath.wangela.apps.twittah.adapters.TweetArrayAdapter.java
com.codepath.wangela.apps.twittah.fragments.HomeTimelineFragment.java
com.codepath.wangela.apps.twittah.fragments.MentionsTimelineFragment.java
com.codepath.wangela.apps.twittah.fragments.TweetsListFragment.java
com.codepath.wangela.apps.twittah.fragments.UserTimelineFragment.java
com.codepath.wangela.apps.twittah.helpers.TwitterClient.java
com.codepath.wangela.apps.twittah.listeners.EndlessScrollListener.java
com.codepath.wangela.apps.twittah.listeners.SupportFragmentTabListener.java
com.codepath.wangela.apps.twittah.models.Category.java
com.codepath.wangela.apps.twittah.models.Item.java
com.codepath.wangela.apps.twittah.models.SampleModel.java
com.codepath.wangela.apps.twittah.models.Tweet.java
com.codepath.wangela.apps.twittah.models.User.java