Android Open Source - SimpleTwitterClient Twitter Client






From Project

Back to project page SimpleTwitterClient.

License

The source code is released under:

MIT License

If you think the Android project SimpleTwitterClient 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.nickrasband.simpletwitterclient;
// w w  w .  java 2 s . c  o  m
import org.scribe.builder.api.Api;
import org.scribe.builder.api.TwitterApi;

import android.content.Context;

import com.codepath.oauth.OAuthBaseClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
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;
    public static final String REST_URL = "https://api.twitter.com/1.1";
    public static final String REST_CONSUMER_KEY = "ZsgzI2WbHAKVTZQpoJqIGw";
    public static final String REST_CONSUMER_SECRET = "vGUVZwwBtcL7meqrINgIde3T6Qoszz8hyUOKUdwqs";
    public static final String REST_CALLBACK_URL = "oauth://simpletwitterclient";
    
    public TwitterClient(Context context) {
        super(context, REST_API_CLASS, REST_URL, REST_CONSUMER_KEY, REST_CONSUMER_SECRET, REST_CALLBACK_URL);
    }
    
    
    public void getHomeTimeline(int count, long max_id, AsyncHttpResponseHandler handler) {
        String apiUrl = getApiUrl("statuses/home_timeline.json");
        RequestParams params = new RequestParams();
        if (count > 0) {
          params.put("count", Integer.toString(count));
        }

        if (max_id != 0) {
          params.put("max_id", Long.toString(max_id));
        }
    
        client.get(apiUrl, params, handler);
    }
    
    // Post a tweet from the authenticated user to Twitter.
    public void postTweet(String message, AsyncHttpResponseHandler handler) {
      String apiUrl = getApiUrl("statuses/update.json");
      RequestParams params = new RequestParams();
      params.put("status", message);
      client.post(apiUrl, params, handler);
    }
    
    // Make sure that the current user is authenticated and get back some information about the user.
    public void getUserCredentials(Boolean includeEntities, Boolean skipStatus, AsyncHttpResponseHandler handler) {
      String apiUrl = getApiUrl("account/verify_credentials.json");
      RequestParams params = new RequestParams();
      
      if (!includeEntities) {
        params.put("include_entities", "false");
      }
      
      if (skipStatus) {
        params.put("skip_status", "true");
      }
      
      client.get(apiUrl, params, handler);
    }
    
    /* 1. Define the endpoint URL with getApiUrl and pass a relative path to the endpoint
     *     i.e getApiUrl("statuses/home_timeline.json");
     * 2. Define the parameters to pass to the request (query or body)
     *    i.e RequestParams params = new RequestParams("foo", "bar");
     * 3. Define the request method and make a call to the client
     *    i.e client.get(apiUrl, params, handler);
     *    i.e client.post(apiUrl, params, handler);
     */
}




Java Source Code List

com.nickrasband.simpletwitterclient.ComposeTweetActivity.java
com.nickrasband.simpletwitterclient.EndlessScrollListener.java
com.nickrasband.simpletwitterclient.LoginActivity.java
com.nickrasband.simpletwitterclient.SimpleTwitterClientApp.java
com.nickrasband.simpletwitterclient.TimelineActivity.java
com.nickrasband.simpletwitterclient.TweetsAdapter.java
com.nickrasband.simpletwitterclient.TwitterClient.java
com.nickrasband.simpletwitterclient.models.Tweet.java
com.nickrasband.simpletwitterclient.models.User.java
eu.erikw.PullToRefreshListView.java