I am using CFML and Twitter4j to return timelines and lists.

I want to return the data from a call to lookupUsers(java.lang.String[] screenNames) via Twitter4j.

I have tried the :-

strList = createObject("java", "java.util.ArrayList");
strList.add(strOriginUser);
originUser = t4j.lookupUsers(strList);

And :-

strUserString = JavaCast("String", strOriginUser);
originUser = t4j.lookupUsers(strUserString);

I know the t4j Object is working as I already use it to get timelines etc but here it is for completeness :-

public function init_twitter() {
    //CONFIGURE twitter4j
    configBuilder = createObject("java", "twitter4j.conf.ConfigurationBuilder");
    configBuilder.setOAuthConsumerKey(#application.twitter_consumer_key#);
    configBuilder.setOAuthConsumerSecret(#application.twitter_consumer_secret#);
    configBuilder.setOAuthAccessToken(#application.twitter_access_token#);
    configBuilder.setOAuthAccessTokenSecret(#application.twitter_access_token_secret#);
    configBuilder.setIncludeEntitiesEnabled(true);
    configBuilder.setJSONStoreEnabled(true);
    config = configBuilder.build();
    twitterFactory = createObject("java", "twitter4j.TwitterFactory").init(config);
    variables.t4j = twitterFactory.getInstance();
    return this;
}

The twitter4j documentations is:-

ResponseList<User> lookupUsers(java.lang.String[] screenNames) throws TwitterException

Return up to 100 users worth of extended information, specified by either ID, screen name, or combination of the two. The author's most recent status (if the authenticating user has permission) will be returned inline. This method calls http://api.twitter.com/1.1/users/lookup.json

Parameters:

screenNames - Specifies the screen names of the users to return.

Returns: users

有帮助吗?

解决方案

It looks like you are trying to pass an ArrayList object into lookupUsers but that method only accepts String[] (an array of Strings) as an argument. So unless CFML does the conversion, I don't think it's going to work.

From a cursory glance at the ColdFusion docs, it looks like CFML can implicitly convert a CFML Array to a Java array, so perhaps the following would work:

screenNames = arrayNew(1);
screenNames[1] = 'Fry';

originUser = t4j.lookupUsers(screenNames);

Alternatively, if you want to keep on using a list there is an ArrayList#toArray(T[]) which could be useful, although I can't say how useful that would be in the CFML.

N.B. Please excuse my CFML code snippet.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top