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.
.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("http://twitter.com/statuses/update.xml"); byte[] b = new String("status="+newStatus).getBytes(HTTP.UTF_8.toString()); ByteArrayEntity be=new ByteArrayEntity(b); req.setEntity(be); HttpResponse res = httpClient.execute(req); |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
37 | |
19 | |
13 | |
13 | |
12 | |
10 | |
10 | |
9 | |
8 | |
8 |