Twitter api: cant set the content and send parameter in the body of HttpPost request


#1

I am working with Twitter api 1.1 Below is the code to get the bearer token from api 1.1. I need to set the content type of the request and send grant type=client_credentials in the body of the request. I am already sending the encoded consumer_key and consumer_secret in the header.

Can someone guide me how can I set the content and send parameter in the body of HttpPost request?


HttpClient httpclient = new DefaultHttpClient();
String consumer_key=“D5fpKNVfBSb06mQFaRn1Qw”;
String consumer_secret=“U47FAia7Mgc3p6Nm7R0DJjSnpz6pS4i3neVyPMGyY”;
String authorization_header_string=consumer_key+":"+consumer_secret;
authorization_header_string=URLEncoder.encode(authorization_header_string, “UTF-8”);
System.out.println(authorization_header_string);
HttpPost httppost = new HttpPost(“https://api.twitter.com/oauth/token?grant_type=client_credentials”);
httppost.setHeader(“Authorization”,authorization_header_string);

     ResponseHandler<String> responseHandler = new BasicResponseHandler();
    String responseBody = httpclient.execute(httppost, responseHandler);
    System.out.println(responseBody);

Thank you so much for your help.