Skip to Content
Product Information

Fun with Twitter ,12Sprints and Android!

In a blog posted earlier ,titled Sprint RESTs on Android! ,we saw how to create 12Sprints activities from Android.

Now let us  take this a step further. Since our entire team (fictitious 🙂 is on twitter we will now tweet the newly created activity URL.

Twitter exposes API to update your status.More on this here Status update API.(Is it possible to send DM to a list in twitter? that way the activity update could be sent to specific teams!)

.format is the format in which the response would be returned. It could be json or xml.

We update the status based on the HTTP response code returned by the create activity API.For successful creation the code is HTTP 201.

To call the twitter API we need to set the Expect 100 request header to false otherwise HTTP error code 417 is returned.

The final code looks like this:

HttpParams basicHttpParams=new BasicHttpParams();

HttpProtocolParams.setUseExpectContinue(basicHttpParams, false);

DefaultHttpClient httpClient=new DefaultHttpClient(basicHttpParams);

UsernamePasswordCredentials cred=new UsernamePasswordCredentials(“twitter username”, “password”);

httpClient.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), cred);

HttpPost req=new HttpPost(““);

byte[] b = new String(“status=”+newStatus).getBytes(HTTP.UTF_8.toString());

ByteArrayEntity be=new ByteArrayEntity(b);


HttpResponse res = httpClient.execute(req);

viola!Activity update shows up on twitter

activity update

Another good idea here would be to pass the result of tweet response to a URL shortner API service just in case our tweet is more that 140 chars in length. I leave this to you!

Be the first to leave a comment
You must be Logged on to comment or reply to a post.