0

I would like to be able to make a request to Twitter with Pentaho's REST client request however this software does not have any concept of oauth. I found this (Implement OAuth in Java)neat java class that I would like to implement with Pentaho's java class tranformation but I am so new to Pentaho this task will be very difficult. I am hoping someone can help me out with this....

Community
  • 1
  • 1
a11hard
  • 1,904
  • 4
  • 19
  • 41

1 Answers1

3

I found this great twitter java library called twitter4J and imported the core classes into the pentaho directory pentaho/design-tools/data-integration/libext and wrote the below custom user java class.

// NO COLLECTION TYPE SAFETY ALLOWED, MUST CAST ALL OBJECTS
import twitter4j.*;
import twitter4j.auth.*;
import twitter4j.conf.*;
//import other libs here

//put your vars here


// Variables
private Twitter twitter = null;

public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException 
{

    Object[] r = getRow();
    if (r==null)
    {
        setOutputDone();
        return false;
    }

    if (first) {
        first=false;

        paging = new Paging();
        paging.setCount(100);

    }

    oauth_user_key = get(Fields.In, "oauth_user_key").getString(r); 
    oauth_user_secret = get(Fields.In, "oauth_user_secret").getString(r); 
    consumer_key = get(Fields.In, "consumer_key").getString(r); 
    consumer_secret = get(Fields.In, "consumer_secret").getString(r); 

    //wierd long/string thing here (pentho compiles java wierd)
    user_id =  get(Fields.In, "source_user_id").getInteger(r);
    Long user = user_id;


    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true)
        .setIncludeEntitiesEnabled(true)
        .setOAuthConsumerKey(consumer_key)
        .setOAuthConsumerSecret(consumer_secret)
        .setOAuthAccessToken(oauth_user_key)
        .setOAuthAccessTokenSecret(oauth_user_secret);

    twitter = new TwitterFactory(cb.build()).getInstance();

    try {
        //be creative with twitter4j here and output rows with results (may require a loop)

    } catch (TwitterException e){
        logDebug(e.getMessage());
        return true;
    }

    logBasic("twitter collect done" );
    return true;
}
a11hard
  • 1,904
  • 4
  • 19
  • 41