Skip to content

Instantly share code, notes, and snippets.

@boazsender
Created November 26, 2010 05:06
Show Gist options
  • Save boazsender/716300 to your computer and use it in GitHub Desktop.
Save boazsender/716300 to your computer and use it in GitHub Desktop.
Twitter API implementations for lists, search.
$(function(){
// Twitter REST API list method
$.getJSON('http://twitter.com/F1LT3R/lists/bocoup/statuses.json?callback=?', function(tweets){
console.log('Twitter REST API results:', tweets);
// This will log an array of objects each representing one twitter post.
// Each object in the array will contain on tweet that looks like this.
/*
[
Object,
Object : {
contributors: null,
coordinates: null,
created_at: "Fri Nov 26 04:41:49 +0000 2010",
favorited: false,
geo: null,
id: 8017557558657025,
id_str: "8017557558657025",
in_reply_to_screen_name: null,
in_reply_to_status_id: null,
in_reply_to_status_id_str: null,
in_reply_to_user_id: null,
in_reply_to_user_id_str: null,
place: null,
retweet_count: null,
retweeted: false,
source: "web",
text: "Almost forgot. I'm thankful for Rose and Alli. Sorry everything else.",
truncated: false,
user: Object,
},
Object,
Object,
Object
]
*/
});
// Twitter Search API general query
$.getJSON('http://search.twitter.com/search.json?q=omg&callback=?', function(tweets){
console.log('Twitter Search API results:', tweets);
// This will log an object representing the entire result set.
// This object will contain information about the search, and
// a results array property containing one object for each tweet.
/*
Object : {
completed_in: 0.02196,
max_id: 7991903949692928,
max_id_str: "7991903949692928",
next_page: "?page=2&max_id=7991903949692928&rpp=5&q=+from%3AF1LT3R",
page: 1,
query: "+from%3AF1LT3R",
refresh_url: "?since_id=7991903949692928&q=+from%3AF1LT3R",
results:[
0: Object : {
created_at: "Thu, 25 Nov 2010 22:47:06 +0000",
from_user: "F1LT3R",
from_user_id: 5212992,
from_user_id_str: "5212992",
geo: null,
id: 7928290484428802,
id_str: "7928290484428802",
iso_language_code: "en",
metadata: Object,
profile_image_url: "http://a1.twimg.com/profile_images/275415881/me_normal.jpg",
source: "<a href="http://www.tweetdeck.com" rel="nofollow">TweetDeck</a>",
text: "iPhone are using the phrase "face"-time. Wonder how Facebook feel about that eh? :)",
to_user_id: null,
to_user_id_str: null
},
1: Object,
2: Object,
3: Object,
4: Object
],
results_per_page: 5,
since_id: 0,
since_id_str: "0"
}
*/
});
});
<!DOCTYPE html>
<html>
<head>
<title>Twitter Search Plugin</title>
<script src="http://code.jquery.com/jquery-1.4.4.js"></script>
<script src="twitter-api-boilerplate.js"></script>
</head>
<body>
<h1>Open your JavaScript console</h1>
</body>
</html>
$(function(){
// Twitter REST API list method
$.getJSON('http://twitter.com/F1LT3R/lists/bocoup/statuses.json?callback=?', function(tweets){
console.log('Twitter REST API results:', tweets);
});
// Twitter Search API general query
$.getJSON('http://search.twitter.com/search.json?q=omg&callback=?', function(tweets){
console.log('Twitter Search API results:', tweets);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment