{"id":2291,"date":"2010-12-14T21:20:28","date_gmt":"2010-12-14T15:50:28","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=2291"},"modified":"2010-12-14T21:20:28","modified_gmt":"2010-12-14T15:50:28","slug":"posting-messages-on-facebook-wall-using-graph-api","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/posting-messages-on-facebook-wall-using-graph-api\/","title":{"rendered":"Posting messages on facebook wall using graph api"},"content":{"rendered":"<p>Firstly ,you need to  <a href=\"http:\/\/www.tothenew.com\/blog\/integrate-java-application-with-facebook-using-graph-api\/\" target=\"_blank\">connect<\/a> with facebook.<\/p>\n<p>Once you have facebook access token you can post messages on the facebook wall using the below code.<\/p>\n<blockquote>\n<pre lang=\"groovy\">\r\nvoid postMessage(String facebookAccessToken, String message, String facebookId)  {\r\n            StringBuilder stringBuilder = new StringBuilder(\"access_token=\");\r\n            stringBuilder.append(URLEncoder.encode(facebookAccessToken, \"UTF-8\"));\r\n            stringBuilder.append(\"&message=\");\r\n            stringBuilder.append(URLEncoder.encode(message, \"UTF-8\"));\r\n            URL url = new URL(\"https:\/\/graph.facebook.com\/${facebookId}\/feed\");\r\n            HttpURLConnection connection\r\n            try {\r\n                connection = (HttpURLConnection) url.openConnection();\r\n                connection.setDoOutput(true);\r\n                connection.setRequestMethod(\"POST\");\r\n                connection.setRequestProperty(\"Content-Type\", \"application\/x-www-form-urlencoded\");\r\n                connection.setRequestProperty(\"Content-Length\", \"\" + stringBuilder.toString().length());\r\n                OutputStreamWriter outputStreamWriter = new OutputStreamWriter(connection.getOutputStream());\r\n                outputStreamWriter.write(stringBuilder.toString());\r\n                outputStreamWriter.flush();\r\n            } finally {\r\n                connection?.disconnect()\r\n            }\r\n    }\r\n <\/pre>\n<\/blockquote>\n<p>Hope this helped!<\/p>\n<p>Cheers!<\/p>\n<p>Anshul Sharma<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Firstly ,you need to connect with facebook. Once you have facebook access token you can post messages on the facebook wall using the below code. void postMessage(String facebookAccessToken, String message, String facebookId) { StringBuilder stringBuilder = new StringBuilder(&#8220;access_token=&#8221;); stringBuilder.append(URLEncoder.encode(facebookAccessToken, &#8220;UTF-8&#8221;)); stringBuilder.append(&#8220;&#038;message=&#8221;); stringBuilder.append(URLEncoder.encode(message, &#8220;UTF-8&#8221;)); URL url = new URL(&#8220;https:\/\/graph.facebook.com\/${facebookId}\/feed&#8221;); HttpURLConnection connection try { connection = (HttpURLConnection) [&hellip;]<\/p>\n","protected":false},"author":21,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":5},"categories":[7],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/2291"}],"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\/21"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=2291"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/2291\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=2291"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=2291"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=2291"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}