Example usage for twitter4j HttpParameter HttpParameter

List of usage examples for twitter4j HttpParameter HttpParameter

Introduction

In this page you can find the example usage for twitter4j HttpParameter HttpParameter.

Prototype

public HttpParameter(String name, String fileName, InputStream fileBody) 

Source Link

Usage

From source file:cmu.edu.homework.mediaUpload.AbstractPhotoUploadImpl.java

License:Apache License

private String post() {
    uploadUrl = "https://upload.twitter.com/1.1/media/upload.json";
    HttpParameter[] params = new HttpParameter[1];
    try {//from  w w  w . ja  va2s .c o m
        InputStream is = new FileInputStream(new File(this.photo));
        params[0] = new HttpParameter("media", photo, is);
        postParameter = params;
    } catch (Exception e) {
        e.printStackTrace();
    }
    headers.putAll(client.getRequestHeaders());
    HttpRequest req = new HttpRequest(RequestMethod.POST, uploadUrl, postParameter, null, headers);
    String authheader = oauth.getAuthorizationHeader(req);
    headers.put("Authorization", authheader);
    HttpRequest req2 = new HttpRequest(RequestMethod.POST, uploadUrl, postParameter, null, headers);
    try {
        httpResponse = client.request(req2, null);
        if (httpResponse.getStatusCode() != 202) {
            Log.e("Error from Twitter", "get error in post:" + httpResponse.getStatusCode() + ", details:"
                    + httpResponse.toString());
        }
        return httpResponse.asJSONObject().getString("media_id_string");
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}