List of usage examples for twitter4j HttpParameter HttpParameter
public HttpParameter(String name, boolean value)
From source file:cmu.edu.homework.mediaUpload.AbstractPhotoUploadImpl.java
License:Apache License
@Override public String upload(String photoFileName, InputStream photoBody, String message) throws TwitterException { // this.photo = new HttpParameter("media", photoFileName, photoBody); this.message = new HttpParameter("message", message); return upload(); }
From source file:cmu.edu.homework.mediaUpload.AbstractPhotoUploadImpl.java
License:Apache License
@Override public String upload(File file, String message) throws TwitterException { this.photo = file.getAbsolutePath(); this.message = new HttpParameter("message", message); return upload(); }
From source file:cmu.edu.homework.mediaUpload.AbstractVideoUploadImpl.java
License:Apache License
@Override public String upload(String videoFileName, InputStream videoBody, String message) throws TwitterException { // this.video = new HttpParameter("media", videoFileName, videoBody); this.message = new HttpParameter("message", message); return upload(); }
From source file:cmu.edu.homework.mediaUpload.AbstractVideoUploadImpl.java
License:Apache License
@Override public String upload(File file, String message) throws TwitterException { this.video = file.getAbsolutePath(); this.message = new HttpParameter("message", message); String media_id = upload();/*www . j a v a 2 s.co m*/ long[] media_ids = new long[1]; media_ids[0] = Long.parseLong(media_id); return media_id; }
From source file:cmu.edu.homework.mediaUpload.AbstractVideoUploadImpl.java
License:Apache License
private String post(String message, long[] media_ids) { String postUrl = "https://api.twitter.com/1.1/statuses/update.json"; HttpParameter[] params = new HttpParameter[2]; params[0] = new HttpParameter("status", message); params[1] = new HttpParameter("media_ids", String.valueOf(media_ids)); postParameter = params;//from w ww. j a va2 s.co m headers.putAll(client.getRequestHeaders()); String authheader = generateVerifyCredentialsAuthorizationHeader("POST"); 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 INIT:" + httpResponse.getStatusCode() + ", details:" + httpResponse.toString()); } return "202"; } catch (Exception e) { e.printStackTrace(); } return "Error"; }
From source file:cmu.edu.homework.mediaUpload.AbstractVideoUploadImpl.java
License:Apache License
private String init() { uploadUrl = "https://upload.twitter.com/1.1/media/upload.json"; HttpParameter[] params = new HttpParameter[3]; params[0] = new HttpParameter("command", "INIT"); long total_bytes = new File(video).length(); params[1] = new HttpParameter("total_bytes", total_bytes); params[2] = new HttpParameter("media_type", "video/mp4"); if (this.postParameter != null && this.postParameter.length > 0) { this.appendHttpParameters(params, this.postParameter); } else {//w w w . java2 s.c o m this.postParameter = params; } 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 INIT:" + httpResponse.getStatusCode() + ", details:" + httpResponse.toString()); } return httpResponse.asJSONObject().getString("media_id_string"); } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:cmu.edu.homework.mediaUpload.AbstractVideoUploadImpl.java
License:Apache License
private String append(String media_id_string) { HttpParameter[] params = new HttpParameter[4]; params[0] = new HttpParameter("command", "APPEND"); params[1] = new HttpParameter("media_id", media_id_string); params[2] = new HttpParameter("segment_index", "0"); try {//from ww w. j ava2 s . com InputStream is = new FileInputStream(new File(video)); params[3] = new HttpParameter("media", video, is); } catch (Exception e) { e.printStackTrace(); } if (this.postParameter != null && this.postParameter.length > 0) { this.appendHttpParameters(params, this.postParameter); } else { this.postParameter = params; } 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 INIT:" + httpResponse.getStatusCode() + ", details:" + httpResponse.toString()); } return httpResponse.asJSONObject().getString("media_id_string"); } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:cmu.edu.homework.mediaUpload.AbstractVideoUploadImpl.java
License:Apache License
private String finalize(String media_id_string) { HttpParameter[] params = new HttpParameter[2]; params[0] = new HttpParameter("command", "FINALIZE"); params[1] = new HttpParameter("media_id", media_id_string); if (this.postParameter != null && this.postParameter.length > 0) { this.appendHttpParameters(params, this.postParameter); } else {//from w w w . j av a2s . c o m this.postParameter = params; } 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 INIT:" + httpResponse.getStatusCode() + ", details:" + httpResponse.toString()); } Log.d(TAG, "Response after finalized:" + httpResponse.asString()); return httpResponse.asJSONObject().getString("media_id_string"); } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:com.daiv.android.twitter.utils.api_helper.APIHelper.java
License:Apache License
/** * Gets the header to verify the user on Twitter * @param twitter Coming from Twitter.getInstance() * @return String of the header to be used with X-Verify-Credentials-Authorization *//*ww w. j a va 2s . c o m*/ public String getAuthrityHeader(Twitter twitter) { try { // gets the system time for the header long time = System.currentTimeMillis() / 1000; long millis = time + 12; // set the necessary parameters List<HttpParameter> oauthHeaderParams = new ArrayList<HttpParameter>(5); oauthHeaderParams.add(new HttpParameter("oauth_consumer_key", AppSettings.TWITTER_CONSUMER_KEY)); oauthHeaderParams.add(new HttpParameter("oauth_signature_method", "HMAC-SHA1")); oauthHeaderParams.add(new HttpParameter("oauth_timestamp", time + "")); oauthHeaderParams.add(new HttpParameter("oauth_nonce", millis + "")); oauthHeaderParams.add(new HttpParameter("oauth_version", "1.0")); oauthHeaderParams.add(new HttpParameter("oauth_token", twitter.getOAuthAccessToken().getToken())); List<HttpParameter> signatureBaseParams = new ArrayList<HttpParameter>(oauthHeaderParams.size()); signatureBaseParams.addAll(oauthHeaderParams); // create the signature StringBuilder base = new StringBuilder("GET").append("&") .append(HttpParameter.encode(constructRequestURL(SERVICE_PROVIDER))).append("&"); base.append(HttpParameter.encode(normalizeRequestParameters(signatureBaseParams))); String oauthBaseString = base.toString(); String signature = generateSignature(oauthBaseString, twitter.getOAuthAccessToken()); oauthHeaderParams.add(new HttpParameter("oauth_signature", signature)); // create the header to post return "OAuth " + encodeParameters(oauthHeaderParams, ",", true); } catch (Exception e) { e.printStackTrace(); return ""; } }