{"id":8442,"date":"2012-09-24T22:46:34","date_gmt":"2012-09-24T17:16:34","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=8442"},"modified":"2012-09-24T22:46:34","modified_gmt":"2012-09-24T17:16:34","slug":"posting-status-update-on-twitter-using-twitter4j","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/posting-status-update-on-twitter-using-twitter4j\/","title":{"rendered":"Posting status update on twitter using Twitter4j"},"content":{"rendered":"<p>Hi,<\/p>\n<p>In the previous <a href=\"http:\/\/www.tothenew.com\/blog\/retweet-a-tweet-using-twitter4j\/\">post<\/a>, we saw how to Retweet any user&#8217;s tweet from our application. In the same project, i needed to post a new tweet on behalf of the authenticating user from the application using Twitter API.<\/p>\n<p>Posting a new status update is quite easy using <a href=\"http:\/\/twitter4j.org\/en\/index.html\">Twitter4j<\/a> library. <\/p>\n<pre>\r\n\r\n<\/pre>\n<p>For making any twitter API calls we need to have twitter account <strong>access_token<\/strong> and <strong>access_secret<\/strong>, which we obtains after authorizing\/connecting twitter account with the application as mentioned in this <a href=\"http:\/\/www.tothenew.com\/blog\/integrating-java-application-with-twitter\/\">blog<\/a>.<\/p>\n<pre>\r\n\r\n<\/pre>\n<p><strong>Pre-Requirements:-<\/strong><br \/>\n[java]<br \/>\n       String consumerKey = CONSUMER_KEY \/\/ key obtained after registering app.<br \/>\n       String consumerSecret =CONSUMER_SECRET \/\/ secret key obtained from the registered app.<br \/>\n       String twitterToken = USER_TWITTER_TOKEN<br \/>\n       \/\/ access_token received by authentication user&#8217;s twitter account<br \/>\n       String twitterSecret= USER_TWITTER_SECRET<br \/>\n        \/\/ access_secret obtained by authentication user&#8217;s twitter account<br \/>\n       String statusUpdate = \/\/ message to be posted<\/p>\n<p>[\/java]<\/p>\n<p><strong>Code to create new Twitter Post :-<\/strong><\/p>\n<p>[java]<br \/>\n        TwitterFactory factory = new TwitterFactory()<br \/>\n        Twitter twitter = factory.getInstance()<br \/>\n        twitter.setOAuthConsumer(consumerKey, consumerSecret)<br \/>\n        AccessToken accessToken = new AccessToken(twitterToken, twitterSecret)<br \/>\n        twitter.setOAuthAccessToken(accessToken)<br \/>\n        Status status = twitter.updateStatus(statusUpdate)<br \/>\n[\/java]<\/p>\n<p>So, this code will create a new Twitter post on behalf of the authenticating user using API calls.<\/p>\n<p>Hope this helps.<\/p>\n<pre>\r\n\r\n<\/pre>\n<p>Other Blogs:-<\/p>\n<p><a href=\"http:\/\/www.tothenew.com\/blog\/sending-direct-message-to-a-twitter-user-using-twitter4j\/\">Send Direct Message using Twitter4j<\/a><br \/>\n<a href=\"http:\/\/www.tothenew.com\/blog\/mark-tweet-as-favorite-using-twitter4j\/\">Mark Tweet as Favorite using Twitter4j<\/a><br \/>\n<a href=\"http:\/\/www.tothenew.com\/blog\/reply-to-a-user-tweet-using-twitter4j\/\">Reply to a tweet using Twitter4j<\/a><br \/>\n<a href='http:\/\/www.tothenew.com\/blog\/retweet-a-tweet-using-twitter4j\/'>Retweet a tweet using Twitter4j<\/a><\/p>\n<pre>\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Hi, In the previous post, we saw how to Retweet any user&#8217;s tweet from our application. In the same project, i needed to post a new tweet on behalf of the authenticating user from the application using Twitter API. Posting a new status update is quite easy using Twitter4j library. For making any twitter API [&hellip;]<\/p>\n","protected":false},"author":19,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":3},"categories":[7],"tags":[706,700,1047,873,1018,1052,1027,1019],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/8442"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/19"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=8442"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/8442\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=8442"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=8442"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=8442"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}