Hi, here our code
public synchronized String sendPromotableTweet( String tweet,String mediaIds) throws Exception {
String url = "https://ads-api.twitter.com/4/accounts/" + this.streamPromotable.getAccountCardId() + "/tweet";
OAuthConsumer oauthConsumer = new CommonsHttpOAuthConsumer(
this.streamPromotable.getConsumerKey(),
this.streamPromotable.getConsumerSecret());
oauthConsumer.setTokenWithSecret(this.streamPromotable.getAccessToken(),
this.streamPromotable.getTokenSecret());
String obj = "";
BufferedReader reader = null;
try {
//JSONObject jreq = new JSONObject();
//jreq.put("text", tweet);
//jreq.put("as_user_id", streamPromotable.getTwitterId());
//jreq.put("trim_user", true);
//String request = jreq.toString();
log.info("sent "+streamPromotable.getTwitterId());
List<NameValuePair> params = new ArrayList();
params.add(new BasicNameValuePair("text", tweet));
//params.add(new BasicNameValuePair("as_user_id", userId + ""));
params.add(new BasicNameValuePair("as_user_id", streamPromotable.getTwitterId() + ""));
params.add(new BasicNameValuePair("trim_user", "true"));
if(!mediaIds.isEmpty()) {
params.add(new BasicNameValuePair("media_ids", mediaIds));
}
this.log.info("request sendPromotableTweet " + " media_ids="+mediaIds);
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(params));
oauthConsumer.sign(httpPost);
HttpResponse httpResponseInit = this.httpClient.execute(httpPost);
this.log.info(
"status welcome message default code init : " + httpResponseInit.getStatusLine().getStatusCode());
reader = new BufferedReader(new InputStreamReader(httpResponseInit.getEntity().getContent()));
String str;
while ((str = reader.readLine()) != null) {
obj = obj + str;
}
if (reader != null) {
reader.close();
}
this.log.info("result " + obj);
} catch (Exception ex) {
ex.printStackTrace();
this.log.error(com.gdilab.autoresponse.core.util.Utils.logException(ex));
throw ex;
}
return obj;
}