Git Product home page Git Product logo

java-twitter-api's Introduction

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.