Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
0 Kudos

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 http://twitter.com/statuses/update.format 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("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);



viola!Activity update shows up on twitter



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!