Coder Social home page Coder Social logo

jquery.gettweet.js's Introduction

#jquery.getTweet.js -An easy to use tweet fetcher.

####Created by Jonathan Cutrell ####twitter: @jcutrell ####email: [email protected] ####github: jcutrell

As long as twitter continues to serve JSON the way that they are currently doing, this plugin will work.

Make sure you include jQuery before the plugin, (ex:)

	<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

It's pretty simple... Two methods.


##First method

The easiest way to use the plugin; grabs the latest tweet for @username and puts it inside the element corresponding to the matching selector.

$(".coolclass").getTweet("username");

This will replace all of the html in elements matching the .someclass selector with a <\ul id="getTweet"> Each tweet will be wrapped in an <\li> with a class of "tweet".

$(".someclass").getTweet("username", 4);

#####This method also adds markup to the tweets; @username will change to "@username", and #hashtag will change to the twitter hash search path.


##Second method

This method passes an array to the callback function. $.getTweet()

This method will grab the latest 5 tweets and pass them into the callback function.

$.getTweet("username", 5, function(data){ // do something here })

This method can also take a (0-indexed) array to grab, in this instance, tweets 4-10 from your latest tweets. This array is passed to the callback.

$.getTweet("username", [3, 9], function(data){ // do something here })

This will return the same array as the previous example, in reverse order.

$.getTweet("username", [9, 3], function(data){ // do something })

The simplest usage of $.getTweet - grabs the latest tweet and stores it at the array[0] position.

$.getTweet("username", function(data){ // do something })


The plugin is intentionally low on features; in the future, I may add a few features, as geolocation, etc make their way.

I have made the public twitter json object available to use via the $.getTweet.api object. The following function, for instance, puts a span around the creation time of a set of tweets, and appends them to an element with an id of "targetDiv".

$.getTweet('username', [20, 30], function(data){ $.each($.getTweet.api, function(i, item){
		$('<span>"' + item.created_at + '"</span>').appendTo('#targetDiv')
		});
	});

///////////////////////////

###A few considerations...

  1. The twitter api isn't really extremely friendly to javascript developers. They provide JSON data, but in general, javascript and twitter don't play too well together.
  2. With that said, the tweets that are accessible through this plugin are only the public tweets. This means that while you may request for 50 tweets, 45 may be shown (because, for instance, of a retweet of an account that was private).
  3. Twitter is a busy place. Be mindful of how slow it can be to gather large amounts of data from Twitter.
  4. Pagination is not currently supported with this plugin.

jquery.gettweet.js's People

Stargazers

Filipe Goncalves avatar

Watchers

Filipe Goncalves avatar James Cloos avatar

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.