Android Open Source - SimpleTwitterClient Twitter Client






From Project

Back to project page SimpleTwitterClient.

License

The source code is released under:

Copyright (c) 2014 Keithen Hayenga Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the So...

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.codepath.apps.basictwitter;
// w  ww  . java  2 s.  c  o  m
import org.scribe.builder.api.Api;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

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 = org.scribe.builder.api.TwitterApi.class;
    public static final String REST_URL = "https://api.twitter.com/1.1";
    public static final String REST_CONSUMER_KEY = "A3W6hXx3ghZN7bk7WqQBygXUS";
    public static final String REST_CONSUMER_SECRET = "l64drCXwlh8SU2TMhdLitdf1b4CWkoZ3EJxzjYnGp1psIVzzoV";
    public static final String REST_CALLBACK_URL = "oauth://cpbasictweets";
    
    public TwitterClient(Context context) {
        super(context, REST_API_CLASS, REST_URL, REST_CONSUMER_KEY, REST_CONSUMER_SECRET, REST_CALLBACK_URL);
    }
    
    public void getHomeTimeline(AsyncHttpResponseHandler handler) {
        String apiUrl = getApiUrl("statuses/home_timeline.json");
        RequestParams params = new RequestParams();
        params.put("since_id", "1");
        client.get(apiUrl, params, handler);
    }
    
    public void postTweet(AsyncHttpResponseHandler handler, String tweetMsg) {
        String apiUrl = getApiUrl("statuses/update.json");
        RequestParams params = new RequestParams();
        params.put("status", tweetMsg);
        client.post(apiUrl, params, handler);
    }
    
////    return POST(urls[0],person);
/*
    Parameters
    status required

    The text of your status update, typically up to 140 characters. URL encode as necessary. t.co link wrapping may effect character counts.
    // http://api.rottentomatoes.com/api/public/v1.0/lists/movies/box_office.json?apikey=<key>
    public void getBoxOfficeMovies(JsonHttpResponseHandler handler) {
        String url = getApiUrl("lists/movies/box_office.json");
        RequestParams params = new RequestParams("apikey", API_KEY);
        client.get(url, params, handler);
    }
*/
    
    // CHANGE THIS
    // DEFINE METHODS for different API endpoints here
    /*
    public void getInterestingnessList(AsyncHttpResponseHandler handler) {
        String apiUrl = getApiUrl("?nojsoncallback=1&method=flickr.interestingness.getList");
        // Can specify query string params directly or through RequestParams.
        RequestParams params = new RequestParams();
        params.put("format", "json");
        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.codepath.apps.basictwitter.ComposeActivity.java
com.codepath.apps.basictwitter.LoginActivity.java
com.codepath.apps.basictwitter.TimelineActivity.java
com.codepath.apps.basictwitter.TweetArrayAdapter.java
com.codepath.apps.basictwitter.TwitterApplication.java
com.codepath.apps.basictwitter.TwitterClient.java
com.codepath.apps.basictwitter.models.SampleModel.java
com.codepath.apps.basictwitter.models.Tweet.java
com.codepath.apps.basictwitter.models.User.java