gpt4 book ai didi

java - 在js或java中为twitter的pentaho客户端生成oauth签名

转载 作者:行者123 更新时间:2023-12-02 07:43:52 25 4
gpt4 key购买 nike

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

最佳答案

我发现了这个很棒的 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;
}

关于java - 在js或java中为twitter的pentaho客户端生成oauth签名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11196921/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com