Consuming Twitter Stream updates with HTTPClient

31/05/2009

A couple of weeks ago Twitter announced a new Stream API . Instead of having to poll for updates, Twitter is sending them your way on HTTP, in real-time.

The streams come into several flavors, some of which providing a sample of the “firehose” - the stream of all updates, some other taking a list of user id in argument and returning updated for those ids only.

One easy way to test the service as twitter suggest is to use curl on spritzer, a feed that will provide you with 400-500k updates everyday. Which is already quite enough to have a good sample of data to make some stats and other analytics.

%curl http://stream.twitter.com/spritzer.json -uYOURUSERNAME:YOURPASSWORD

Here is the sample code if you want to retrieve and process those updates from Java using HTTP Client 4 from Apache.

This code is not optimized at all and should not be used for production! You’ll also need to handle disconnection / reconnection as the feed can suddenly be d/c ( I got it running for more than 5 days without having to reconnect ).

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

public class StreamConsumer {

	public StreamConsumer() throws Exception {

		DefaultHttpClient httpclient = new DefaultHttpClient();

		httpclient.getCredentialsProvider().setCredentials(
				new AuthScope("stream.twitter.com", 80),
				new UsernamePasswordCredentials("username", "password"));

		HttpGet httpget = new HttpGet("http://stream.twitter.com/spritzer.json");

		ResponseHandler<String> responseHandler = new ResponseHandler<String>() {
			public String handleResponse(HttpResponse resp)
					throws ClientProtocolException, IOException {

				BufferedReader r = new BufferedReader(new InputStreamReader(
						resp.getEntity().getContent(), "US-ASCII"));
				while (true)
					System.out.println(r.readLine());
			}
		};

		httpclient.execute(httpget, responseHandler);

	}

	public static void main(String[] args) {

		try {
			StreamConsumer consumer = new StreamConsumer();
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}
No Comments

Twitter rolling out more Ajaxy stuff

1/04/2009

Zac, one of our developers, had some changed in the twitter UI rolled out to him.Twitter is moving to something closer to what Facebook does with their pages structures, using mainly a single page webapp for private resources ( and the # trick to not do full pages reload ) , and keeping all the standalone simple pages on permalinks.So basically, now the link to your replies timelines as seen in the browser will be : http://twitter.com/timeline/home#timeline/repliesAll the existing links are still working and used inside the app and are redirected to the corresponding view in the one page app. Each time you click on a link in the app, you ll get the #path showing up, just like on Facebook where you have links like http://www.facebook.com/home.php?#/home.php?ref=logo for the home  or http://www.facebook.com/home.php?#/inbox/?ref=mb  for the inbox.On the new features side, it seems that Twitter just introduced saved search - which makes a lot of sense with the new page structure since you ll potentially be able to see the number of new updates for your searches without a single page reload.I think this move is quite interesting, and we ll see more and more web app moving to the single page / multi-views paradigm, keeping permalinks for public resources, as there’s a tendency to leave web application opened and have real time updates. This is all about real-time web and Seesmic is moving to that model tootwitter___zbowling-20090401-105356.jpg        twitter___search_-_april_fish-20090401-105608.jpg

2 Comments

#1 San Francisco Photo day

28/01/2009

One of the very cool thing I enjoyed to do in Paris was taking some courses organized by the City Hall. You have a choice of *hundreds* of different courses, from learning languages, to cooking, and to … photography. My photography course was very interesting, not that I learned that much, but more it was an interesting social experience. Being able to compare our different eyes on the same subject or same theme is so inspiring!

The best thing of this course was certainly our monthly outdoor photo shoot. Each first saturday of the month we were given an assignment, invited to express our creativity, and to explore the boundaries of our subject. I remember very well a portrait shoot session at the Bir Hakeim bridge, everybody was cold but so enthusiastic.

Progressively we became friends, and we managed to keep the motivation to continue our outdoor artistic exploration once the course was over, to get together one time a month to share our passion, and then to have a nice brunch or dinner altogether. And now here I am in San Francisco, with nobody to share my photographic eye.

A few weeks ago, I met very briefly with Manuel Guerzoni, and he just had enough time to tell me he s the author of San Francisco Daily Photo

After a few Facebook message exchange we had the same idea of creating a sort of monthly event in San Francisco, like I used to have in Paris. Going outdoor, armed with your camera ( being whatever camera you like, SLR, compact, digital or not, pinhole and plastic lens welcome  ). The San Francisco Photo Days  group were born!

You can now already RSVP for our first event that is scheduled for the 01/31, beginning at Buena Vista park, more infos here

Let’s meet there !

1 Comment

Potrero on the evening

28/01/2009

potrero on the evening

1 Comment

Experimental version of the new Seesmic online !

17/12/2008

Get it while it s still hot at http://new.seesmic.com. The big change for now is a major UI revamp ( which is still undergoing change ). We re also back-filing all the features we have on the black version.

We would love your feedback, so we can iterate and adjust the site just the way you like it. Keep in mind that it s still very experimental and not finished, so we ll certainly break and fix things along the way, but we thought it s already usable enough to be honored by the first feedback !

I ll give more details on some technical aspects a bit later, but just let me tell you I m very proud of the milestone we ve just accomplished here, and very proud of my team! It s only the small visible part of a major change in our infrastructure, a change that will let us make some very cool things in a near future. More on that soon…

For now, just play with the new site, soon we ll add a button to make it your site by default and redirect all your notifications to the new one if you wish it.

We re still having a fast turnaround on bug and features, so don’t be surprised if we break things sometimes !

Looking forward to read your feedback and have fun !

ps : writing this at almost 5am, so please forgive my approximate english !

1 Comment

Merci Lionceau Immobilier !

4/12/2008

Voila deux mois que j ai a present quitte mon 30m2 Parisien, pour mes 160 m2 a San Francisco. Je viens de recevoir aujourd hui ma caution laissee a mon arrivee dans les lieux. Sous forme de cheque, tres pratique a encaisser quand on a demenage a l etranger. Et accompagnee par 350 euros de retenue car le nouveau locataire a voulu faire enlever le jonc de mer que j avais pose. Oh, et le changement de la prise telephonique qui etait cassee a mon arrivee, ainsi qu un neon de cuisine qui sautait tous les mois, le systeme electrique de l appartement laissant a desirer.

350 euros ?!? pour enlever quoi, 10 m2 de tapis ??? C est pres de deux fois plus cher que m a coute ce tapis!!!  Alors forcement c est facile, maintenant que je suis loin, c est plus difficile d aller reclamer. Et tout ca accompagne par une sorte de pseudo facture non-detaillee, d une societe qui ne doit pas connaitre la crise avec ce genre de pratique honteuse.

Alors je dis merci Lionceau Immobilier. J ai vecu dans cet appartement pendant plus de 7 ans, sans jamais un retard de paiement. Quand j y suis arrive tout etait a refaire, et j ai tout refais. Les murs etait fissures, la tapisserie decollee, les canalisations encombrees tous les mois ( et oui avec une installation pas aux normes… je me rappelle ma tete quand le plombier qui est venu nombre de fois m a dit que la solution la plus simple etait de balancer de l acide ds les canalisations pour les deboucher… mais bien sur ! ). Sans parler des toilettes “broyeurs” car l evacuation elle non plus n etait pas aux normes sanitaires. Le carrelage completement fissure dans l appartement, et une insonorisation telle qu on pouvait entendre le voisin aller au petit coin… un appartement de charme comme ils disent… Avec une cage d escalier qui n avait pas ete refait depuis 40 ans ( si, si ), et qui a ete refaite juste avant que je parte ( dans des conditions de travail deplorables par ailleurs ).

Bref ceci est mon coup de gueule, et j en suis a un point ou je m en veux d avoir etait aussi naif pour avoir laisse mon dernier mois de loyer a ces gens peu honnetes, c est surement qu entre temps j ai appris la confiance ici. Ca fait la vie plus agreable, pas d entreloupes ici, les gens sont droits et ca fait du bien. Il y a de la confiance mutuelle, et du respect entre les gens et dans les relations d affaire. Des valeurs que les parisiens devraient un jour apprendre.

Alors si par hasard vous devez faire affaire avec cette agence, faites attention, prenez des photos lors de l etat des lieux a l arrivee. Ou evitez les tout simplement !

3 Comments

How to configure your GTalk for identi.ca in Twhirl

21/07/2008

 I found a bunch of people asking how to configure their GTalk account inside Twhirl to get instant update through XMPP, so I decided to put this little tutorial together.

You can add me here identi.ca/johann

Make sure you have the last version of Twhirl : 0.8.3f 

Twhirl  XMPP support

6 Comments

Twhirl integrating identi.ca and adding XMPP support

21/07/2008

Identi.ca is the new twitter “clone” that is all the rage on the web. Why that ? :

- Identi.ca is free software : get it at laconi.ca

- Identi.ca is federated. Which means it should be easier to scale. Well this one I can t wait to see on a large scale :)

- Ident.ca supports OpenID, OAuth soon, and the Creative Commons licensing. Yea how about that!

- Identi.ca supports XMPP: Oh well if you dont know it yet, XMPP is the next big thing for social messaging. No polling, every update arrive in real time.

So over the last days we ve been in touch with the wonderful Evan to see how we could move forward to support identi.ca in Twhirl . Beside the API that arrived last week made by Zach and helped a lot, Evan also provided us with the needed ATOM payload inside the XMPP messages, and here what it looks like :

<message from=”update@identi.ca/bourdindaemon” type=”chat” to=”fritzy@twhirl.org” >
<body>johann: @fritzy how is XMPP Summit ?</body>
<html xmlns=”http://jabber.org/protocol/xhtml-im”>
<body xmlns=”http://www.w3.org/1999/xhtml”>
<a href=”http://identi.ca/johann” >johann</a>
<a class=”atlink” href=”http://identi.ca/fritzy” >fritzy</a>
</body>
</html>
<entry xmlns=”http://www.w3.org/2005/Atom”>
<source>
<title>johann - Identi.ca</title>
<link href=”http://identi.ca/johann” />
<link rel=”self” href=”http://identi.ca/johann/rss” type=”application/rss+xml” />
<author>
<name>johann</name>
</author>
<icon>http://identi.ca/avatar/2394-96-20080702195604.png</icon>
</source>
<title>johann: @fritzy how is XMPP Summit ?</title>
<summary>johann: @fritzy how is XMPP Summit ?</summary>
<link rel=”alternate” href=”http://identi.ca/notice/125649″ />
<id>http://identi.ca/notice/125649</id>
<published>2008-07-21T17:24:12+00:00</published>
<updated>2008-07-21T17:24:13+00:00</updated>
</entry>
</message>

So a normal jabber client display : johann: “@fritzy how is XMPP Summit ?”

While an XMPP library will be able to extract structured information like the author, icon, full link to the dent, etc…

So basically what we did is creating a XMPP library for AS3 and adding it to our Twhirl client, and voila !

Now Twhirl enable real-time conversation inside identi.ca, and I must say that I m completely addicted to it!

Oh and dont forget to add me !

No Comments

Spielberg, George Lucas and Shia on Seesmic…

17/05/2008

When I think about it… In late June of past year I began to write the first lines of code of seesmic. Today We have Spielberg, Shia, George Lucs and potentially other celebrities who posted on our platform. I m living that in direct with my friend Cyrille (Vinvin) at my apartment, it s pure moment of history…

No Comments

Activity Stream Recursion

18/02/2008

Via Edwin Khodabakchian, Via Dion :

Activity Stream recursion

Love it to see seesmic making his way into the comics :)

2 Comments