0

我希望能够使用 Pentaho 的 REST 客户端请求向 Twitter 发出请求,但是该软件没有任何 oauth 概念。我发现这个(在 Java 中实现 OAuth)整洁的 java 类,我想用 Pentaho 的 java 类转换来实现,但是我对 Pentaho 很陌生,这项任务将非常困难。我希望有人可以帮助我解决这个问题......

4

1 回答 1

3

我找到了这个很棒的 twitter java 库,名为twitter4J,并将核心类导入 pentaho 目录 pentaho/design-tools/data-integration/libext 并编写了下面的自定义用户 java 类。

// 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;
}
于 2012-06-27T13:20:09.713 回答