Tuesday, November 30, 2010

ODI and Twitter

--

Integrating with Twitter may or may not be a need for a organization.
In this post we will look at how to Tweet from ODI.

Twitter exposes API's to manipulate data.
Twitter also enforced OAuth authentication and recommends all client applications to use it.
How the OAuth works is described here and all the related terminology associated with OAuth can be found here.

If you have a Twitter Account , this is what you need to do..

1) Register a Twitter Application-

Sigin into http://dev.twitter.com/ and choose option 2 - Register an App

Make sure you choose Application Type - "Client" as shown below.


































After registering , twitter will generate Consumer Key and Consumer Secret.











































2) Registering Twitter Application from ODI -

Current version of Java (1.6) does not have inbuild libraries to support OAuth authentication. Either end users have to write there own java libraries to get around OAuth and integrate with twitter api's or use open source libraries like jTwitter , scribe , twitter4j , etc.

In this post, I will be using twitter4j api's (jar file) which can be downloaded from here.

I have created an ODI open tool (TwitterRegistrationODI) to register any twitter application for any twitter account. This will generate the Access Token and Token Secret required for integrating with twitter API's.

The open tool code can be downloaded from here. You need to compile, add your own icon or any free to use icon and create the JAR files. The code was developed using ODI11g.

Add the jar files to your agent path and client user path.

Add the Open tool to ODI using the menu option "ODI -> ADD/Remove Open Tools ..  "






























































Add the Open tool to a package to execute it.

This open tool requires input - Consumer Key , Consumer Secret and Output token file (Access Token and Token Secret will be written to this file). There are other optional proxy parameters which can be set as per the environment.

























Executing the step will pop up a window with URL to authorize the twitter application.















Copy the URL. Use any browser and grant the Twitter application access by logging with your twitter account.
























This will generate a PINCODE which is needed to generate Access Token and Token Secret.
























Goback to ODI and hit enter and this will popup another window. Enter the PINCODE.




Success Message is displayed , if access token and token secret are generated successfully.


The output file has the Access Token and Token Secret.




Note: This process of generating Access Token and Token Secret is needed only once. If the consumer key and consumer token are reset for a twitter application, then the new access token and token secret needs to regenerated.


3) Tweeting from ODI - 

Created another Open tool (TwitterODI). This open tool will be used to tweet from ODI.

The open tool can be downloaded from here. You need to compile, add your own icon or any free to use icon and create the JAR files. The code was developed using ODI11g.

Add the jar file to your agent path and client user path. Import the open tool.

Add it to a package, set the parameters and execute.






















Execute the step/package. Signin into Twitter and here we have our message.


































This Open tool can be modified further to do other things like getting new tweets , searching tweets , etc..but off course its limited to api's provided by twitter4j.
In my opinion its a complete library.


--

3 comments:

  1. Great post.

    Are there any step by step tutorials to create an Open tool

    ReplyDelete
  2. Hi Uli,

    Thanks. I don't know of any tutorial but this is what i did.

    I have used the ODI sample open tool code provided in ODI10g installation to create a sample code for 11g. The information provided over here was extremely helpful to change the old classes to new classes
    http://download.oracle.com/docs/cd/E14571_01/integrate.1111/e12643/appendix_a.htm#CEGGCCJC

    I found compiling the code using Eclipse was the easiest way. Just added the required jar files as external libraries from the ODI_HOME\oracledi.sdk\lib to the java project in Eclipse. Compiled and generated the jar files.

    Added the jar files to userlib directories of client and agent. Then added the open tool using the ODI Studio.

    The most comfortable way to test is using the startcmd. It's little frustrating to log into ODI and test it via package for every code change.

    Hope this is helpful.

    ReplyDelete
  3. I am getting below error.
    Caused by: 401:Authentication credentials (https://dev.twitter.com/docs/auth) were missing or incorrect. Ensure that you have set valid consumer key/secret, access token/secret, and the system clock is in sync.
    error - Could not authenticate with OAuth.
    request - /1/statuses/update.json

    ReplyDelete