{"id":51281,"date":"2017-09-14T08:55:37","date_gmt":"2017-09-14T03:25:37","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=51281"},"modified":"2017-09-14T10:03:07","modified_gmt":"2017-09-14T04:33:07","slug":"twitter-api-integration-with-aem-using-talend","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/twitter-api-integration-with-aem-using-talend\/","title":{"rendered":"Twitter API Integration with AEM Using Talend"},"content":{"rendered":"<p>Recently, I came across an interesting use case to fetch tweets from Twitter and post it to <a title=\"AEM Development\" href=\"http:\/\/www.tothenew.com\/wcm\/cq-aem-development-consulting\">AEM instance<\/a>. Since tweets content can be huge and this use case is similar to that of migration, involving extraction, transformation, and loading of the content, I decided to use an <a href=\"http:\/\/www.tothenew.com\/blog\/advantages-of-an-etl-tool-in-content-migration\/\">ETL tool<\/a>\u00a0called Talend.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-51753 size-full\" title=\"Talend\" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/09\/Screenshot-from-2017-09-07-16-43-10.png\" alt=\"talend twitter component in AEM\" width=\"623\" height=\"231\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2017\/09\/Screenshot-from-2017-09-07-16-43-10.png 623w, \/blog\/wp-ttn-blog\/uploads\/2017\/09\/Screenshot-from-2017-09-07-16-43-10-300x111.png 300w\" sizes=\"(max-width: 623px) 100vw, 623px\" \/><\/p>\n<p><strong><span style=\"font-weight: 400;\"><a title=\"Talend\" href=\"http:\/\/www.tothenew.com\/blog\/talend-passing-values-from-parent-job-to-child-job\/\">Talend<\/a> is a leading open source integration software provider. It has set of <\/span><a href=\"http:\/\/gabrielebaldassarre.com\/talend\/twitter-components-talend\/\"><span style=\"font-weight: 400;\">Twitter components pack<\/span><\/a><span style=\"font-weight: 400;\"> \u00a0based on <\/span><a href=\"http:\/\/twitter4j.org\/en\/\"><span style=\"font-weight: 400;\">twitter4j<\/span><\/a><span style=\"font-weight: 400;\"> library which can help you connect to both <\/span><b>twitter API<\/b><span style=\"font-weight: 400;\"> (in case you want to gather past tweets to build a big dataset, though you can fetch tweets from last one week only at max, as mentioned in <\/span><a href=\"https:\/\/dev.twitter.com\/rest\/public\/search\"><span style=\"font-weight: 400;\">Twitter Developer Documentation<\/span><\/a><span style=\"font-weight: 400;\">) and<\/span><b> twitter stream API<\/b><span style=\"font-weight: 400;\"> (streams the live tweets).<\/span><\/strong><\/p>\n<p><span style=\"font-weight: 400;\">We just need to define the queries in &#8220;tTwitterStreamInput&#8221; or &#8220;tTwitterInput&#8221; component based on our requirement of tweet source then we can post these result to AEM using HTTP post request.<\/span><\/p>\n<p>Below are few simple steps that can be followed to fetch the tweets and post it to the AEM instance:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-51754 size-full\" title=\"steps to fetch the tweets and post to AEM instance\" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/09\/Screenshot-from-2017-09-05-13-05-20.png\" alt=\"steps to fetch the tweets and post to AEM instance\" width=\"1207\" height=\"273\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2017\/09\/Screenshot-from-2017-09-05-13-05-20.png 1207w, \/blog\/wp-ttn-blog\/uploads\/2017\/09\/Screenshot-from-2017-09-05-13-05-20-300x67.png 300w, \/blog\/wp-ttn-blog\/uploads\/2017\/09\/Screenshot-from-2017-09-05-13-05-20-1024x231.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2017\/09\/Screenshot-from-2017-09-05-13-05-20-624x141.png 624w\" sizes=\"(max-width: 1207px) 100vw, 1207px\" \/><\/p>\n<p><b>Step 1: <\/b><span style=\"font-weight: 400;\">Create your own <\/span><a href=\"https:\/\/apps.twitter.com\/\"><span style=\"font-weight: 400;\">twitter application<\/span><\/a><span style=\"font-weight: 400;\"> as you can not use the APIs anonymously. Follow the instructions from this <\/span><a href=\"http:\/\/docs.inboundnow.com\/guide\/create-twitter-application\/\"><span style=\"font-weight: 400;\">link<\/span><\/a><span style=\"font-weight: 400;\"> to do the same.<\/span><\/p>\n<p><b>Step 2: <\/b><span style=\"font-weight: 400;\">Install <\/span><a href=\"http:\/\/gabrielebaldassarre.com\/talend\/twitter-components-talend\/\"><span style=\"font-weight: 400;\">Twitter components pack<\/span><\/a><span style=\"font-weight: 400;\"> in your Talend instance. These components are not available in Talend by default. You&#8217;ll have to <\/span><a href=\"https:\/\/gabrielebaldassarre.com\/talend\/twitter-components-talend\/\"><span style=\"font-weight: 400;\">download<\/span><\/a><span style=\"font-weight: 400;\"> and install them manually. Follow the instructions from this <\/span><a href=\"https:\/\/gabrielebaldassarre.com\/2014\/05\/18\/install-custom-components-talend-open-studio\/\"><span style=\"font-weight: 400;\">link<\/span><\/a><span style=\"font-weight: 400;\"> to install the components in Talend.<\/span><\/p>\n<p><strong><b>Step3:\u00a0<\/b><span style=\"font-weight: 400;\">Restart your instance and create a new job. Drag \u00a0tTwitterOAuth, tTwitterStreamInput , tJavaRow and \u00a0tTwitterOAuthClose from the components palette. Connect them as per the below diagram:<\/span><\/strong><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-51483 size-full\" title=\"Job twitter_migration http_post\" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/08\/Screenshot-from-2017-08-19-02-14-25.png\" alt=\"Job twitter migration http_post AEM\" width=\"640\" height=\"310\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2017\/08\/Screenshot-from-2017-08-19-02-14-25.png 640w, \/blog\/wp-ttn-blog\/uploads\/2017\/08\/Screenshot-from-2017-08-19-02-14-25-300x145.png 300w, \/blog\/wp-ttn-blog\/uploads\/2017\/08\/Screenshot-from-2017-08-19-02-14-25-624x302.png 624w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/p>\n<p><strong><span style=\"font-weight: 400;\"> Select the <\/span><a href=\"https:\/\/gabrielebaldassarre.com\/talend\/ttwitteroauth\/\"><span style=\"font-weight: 400;\">tTwitterOAuth<\/span><\/a><span style=\"font-weight: 400;\"> component, which provides the connector facilities to authenticate against a Twitter App using Twitter OAuth authentication system and fills the fields with the strings you got from your Twitter App API keys page. In this context, API and Consumer are synonyms. You can choose the connection type here based on your requirement.<\/span><\/strong><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-51490 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/08\/oAuth.png\" alt=\"twitter and talend authorization \" width=\"787\" height=\"255\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2017\/08\/oAuth.png 787w, \/blog\/wp-ttn-blog\/uploads\/2017\/08\/oAuth-300x97.png 300w, \/blog\/wp-ttn-blog\/uploads\/2017\/08\/oAuth-624x202.png 624w\" sizes=\"(max-width: 787px) 100vw, 787px\" \/><\/p>\n<p><em><strong>I have used\u00a0<a href=\"https:\/\/gabrielebaldassarre.com\/talend\/ttwitterinput\/\">tTwitterStreamInput<\/a> which gives only structured data as an output. You can also use\u00a0<a href=\"https:\/\/gabrielebaldassarre.com\/talend\/ttwitterinput\/\" target=\"_blank\">tTwitterInput<\/a> component, which provides\u00a0whole JSON response from twitter API.<\/strong><\/em><\/p>\n<p>Write your query in the tTwitterStreamInput component, create a schema and do the column mapping of Output.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-51710 size-full\" title=\"tTwitterStreamInput\" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/09\/Screenshot-from-2017-09-01-12-13-37.png\" alt=\"tTwitterStreamInput AEM twitter integration\" width=\"1229\" height=\"611\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2017\/09\/Screenshot-from-2017-09-01-12-13-37.png 1229w, \/blog\/wp-ttn-blog\/uploads\/2017\/09\/Screenshot-from-2017-09-01-12-13-37-300x149.png 300w, \/blog\/wp-ttn-blog\/uploads\/2017\/09\/Screenshot-from-2017-09-01-12-13-37-1024x509.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2017\/09\/Screenshot-from-2017-09-01-12-13-37-624x310.png 624w\" sizes=\"(max-width: 1229px) 100vw, 1229px\" \/><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-51711 size-full\" title=\"schema of tTwitterStreamInput\" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/09\/Screenshot-from-2017-09-01-12-15-23.png\" alt=\"schema of tTwitterStreamInput talend twitter example\" width=\"767\" height=\"405\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2017\/09\/Screenshot-from-2017-09-01-12-15-23.png 767w, \/blog\/wp-ttn-blog\/uploads\/2017\/09\/Screenshot-from-2017-09-01-12-15-23-300x158.png 300w, \/blog\/wp-ttn-blog\/uploads\/2017\/09\/Screenshot-from-2017-09-01-12-15-23-624x329.png 624w\" sizes=\"(max-width: 767px) 100vw, 767px\" \/><\/p>\n<p>You can limit the number of tweets you want in one job in this component.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-51491 size-full\" title=\"tTwitterStreamInput\" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/08\/input.png\" alt=\"tTwitterStreamInput  twitter talend components\" width=\"634\" height=\"201\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2017\/08\/input.png 634w, \/blog\/wp-ttn-blog\/uploads\/2017\/08\/input-300x95.png 300w, \/blog\/wp-ttn-blog\/uploads\/2017\/08\/input-624x197.png 624w\" sizes=\"(max-width: 634px) 100vw, 634px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Connect the output to the tJavaRow in which a custom code can be written to post the data to the AEM instance. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">I had created a nt:unstructured node corresponding to each tweet in JCR through HTTP post request. <\/span><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-51760 size-full\" title=\"creating a nt:unstructured node \" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/09\/Screenshot-from-2017-09-07-17-38-33.png\" alt=\"creating a nt:unstructured node  twitter input talend\" width=\"729\" height=\"264\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2017\/09\/Screenshot-from-2017-09-07-17-38-33.png 729w, \/blog\/wp-ttn-blog\/uploads\/2017\/09\/Screenshot-from-2017-09-07-17-38-33-300x108.png 300w, \/blog\/wp-ttn-blog\/uploads\/2017\/09\/Screenshot-from-2017-09-07-17-38-33-624x225.png 624w\" sizes=\"(max-width: 729px) 100vw, 729px\" \/><\/p>\n<p>Alternatively, you can use tHttpRequest component to post the tweets to your AEM instance.<\/p>\n<p><strong><span style=\"font-weight: 400;\">Select the connection to be closed in <\/span><a href=\"https:\/\/gabrielebaldassarre.com\/talend\/ttwitteroauthclose\/\"><span style=\"font-weight: 400;\">tTwitterOAuthClose<\/span><\/a><span style=\"font-weight: 400;\"> component. It will close the connection on completion of sub-job.<\/span><\/strong><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-51714 size-full\" title=\" tTwitterOAuthClose \" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/09\/Screenshot-from-2017-09-01-12-22-51.png\" alt=\" tTwitterOAuthClose  how to install talend custom component\" width=\"686\" height=\"187\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2017\/09\/Screenshot-from-2017-09-01-12-22-51.png 686w, \/blog\/wp-ttn-blog\/uploads\/2017\/09\/Screenshot-from-2017-09-01-12-22-51-300x81.png 300w, \/blog\/wp-ttn-blog\/uploads\/2017\/09\/Screenshot-from-2017-09-01-12-22-51-624x170.png 624w\" sizes=\"(max-width: 686px) 100vw, 686px\" \/><\/p>\n<p><strong><span style=\"font-weight: 400;\">Hope you find the blog helpful !!!<\/span><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently, I came across an interesting use case to fetch tweets from Twitter and post it to AEM instance. Since tweets content can be huge and this use case is similar to that of migration, involving extraction, transformation, and loading of the content, I decided to use an ETL tool\u00a0called Talend. Talend is a leading [&hellip;]<\/p>\n","protected":false},"author":1019,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":5},"categories":[1994,1,4488],"tags":[4847,4394,1832,1415,4229,4458,1157,3361,2008,1018,4732],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/51281"}],"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\/1019"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=51281"}],"version-history":[{"count":23,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/51281\/revisions"}],"predecessor-version":[{"id":51713,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/51281\/revisions\/51713"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=51281"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=51281"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=51281"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}