4

I have installed the twitter4j.jar in ColdFusion and it is working. I can post a tweet using cfscript, no problem. I can also upload an image and tweet at same time. I just cannot upload an image and post a tweet and have the tweet show the image?

 <cfscript>
    configBuilder = createObject("java", "twitter4j.conf.ConfigurationBuilder");
    configBuilder.setOAuthConsumerKey('#consumerKey#');
    configBuilder.setOAuthConsumerSecret('#consumerSecret#');
    configBuilder.setOAuthAccessToken('#accessToken#');
    configBuilder.setOAuthAccessTokenSecret('#accessTokenSecret#');
    config = configBuilder.build();

    twitterFactory = createObject("java", "twitter4j.TwitterFactory").init(config);
    twitter = twitterFactory.getInstance();
    //twitterimage=twitter.ImageUploadFactory.getInstance();

    screenName = twitter.getScreenName();
    //followers_list= twitter.getfollowerslist();

    updateStatus1= twitter.UploadMedia(createObject('java','java.io.File').init('c:\\31CC6E16-B55F-704E-C1A14391632DCFD2_medium.jpg'));      
    updateStatus2 = twitter.updateStatus("Whats Up39");

    id = updateStatus2.getId(); // id of the status posted
</cfscript> 

After running the script it returns

Tweet ID:580354904000192513
Pic ID:580354903106682880

So I know the image is uploading. The tweet is there, but no image. Any ideas on what I am doing wrong?

Leigh
  • 28,765
  • 10
  • 55
  • 103
  • It looks to me like you're sending two different statuses: one with the text, one with the image. So, yeah, they'd be separate. GOogling a bit, I found this other S/O answer showing sending text and image n the one status message: http://stackoverflow.com/a/12740436/894061. Does that work? – Adam Cameron Mar 24 '15 at 13:55
  • No I have tryed that route and did not seem to work in the CF11. But I I will re look at it as it took a long time to work around `updateStatus1= twitter.UploadMedia(createObject('java','java.io.File').init('c:\\31CC6E16-B55F-704E-C1A14391632DCFD2_medium.jpg'));` And I may have been out in left field. – Manuel King Mar 24 '15 at 14:06

1 Answers1

0

After a long time researching and trials on my own, I've found this is the code to use:

<cfscript>
configBuilder = createObject("java", "twitter4j.conf.ConfigurationBuilder");
configBuilder.setOAuthConsumerKey('#OAuthConsumerKey#');
configBuilder.setOAuthConsumerSecret('#OAuthConsumerSecret#');
configBuilder.setOAuthAccessToken('#OAuthAccessToken#');
configBuilder.setOAuthAccessTokenSecret('#OAuthAccessTokenSecret#');
config = configBuilder.build();

imageFactory = createObject("java", "twitter4j.media.ImageUploadFactory").init(config);
image = imageFactory.getInstance();

updateStatus = image.upload(createObject('java','java.io.File').init('C:\Path\To\Your\Image.jpg'), 'Your Message');
</cfscript>
Jules
  • 1,941
  • 15
  • 18