ronrihoo / Java-Twitter-API

A light Twitter API for Java.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Java Twitter API

Release

A light Twitter API for Java.

Setup

  1. Either build the JAR or download it from the latest release

  2. Create a folder, "lib", in the directory of a new/existing project

  3. Move or copy the JAR file into the lib folder

  4. Add the JAR file to the build path

    IDEA: From the Project window, select and right-click the lib folder, then click Add as Library...

    Eclipse: From the Package Explorer, select and right-click the JAR file, then select Build and click Add to Build Path

Usage

  1. In a Java source file, import the API
import twitterapi.TwitterApi;
  1. Create an instance of the API using the consumer key and secret acquired from Twitter (pass both as strings)
TwitterApi twitterApi = new TwitterApi(consumerKey, consumerSecret);
  1. Invoke authentication
twitterApi.authenticate();
  1. Pass a query to the apiCall(String) method
String apiCallUrl = "https://api.twitter.com/1.1/trends/place.json?id=1";
twitterApi.apiCall(apiCallUrl);
  1. Parse top ten trends
twitterApi.parseTopTenTwitterTrends();
  1. Get results
String topTenTrends = "Trends: " + twitterApi.getTrendsStr();

A Complete Example

import twitterapi.TwitterApi;

public class Main {

    public static void main(String[] args) {
        run();
    }

    public static void run() {
        String apiCallUrl = "https://api.twitter.com/1.1/trends/place.json?id=1";
        String consumerKey = "place-key-here";
        String consumerSecret = "place-secret-here";
        TwitterApi twitterApi = new TwitterApi(consumerKey, consumerSecret);
        twitterApi.authenticate();
        twitterApi.apiCall(apiCallUrl);
        twitterApi.parseTopTenTwitterTrends();
        System.out.println("Trends: " + twitterApi.getTrendsStr());
    }

}

API Reference

authenticate(String)

    Connects to Twitter's web API service to authenticate credentials

apiCall(String)

    Queries the Twitter web API based on the given URL and retrieves the results

parseTopTenTwitterTrends()

    Parses the top ten trends from the retrieved results

getTrendsStr()

    Returns the retrieved/parsed results in a string

Note: This API includes more methods; however, this covers the majority of its functionality at this time.

Contributing

All pull requests are welcome.

About

A light Twitter API for Java.


Languages

Language:Java 100.0%