Why are you using a Java lib when there is an amazing CF project that does 
the same?

http://monkehtweet.riaforge.org/

Guust Nieuwenhuis

Adobe Community Professional

Mobile: +32 497 33 04 91
Skype: guustnieuwenhuis
Email: i...@lagaffe.be 

----------------------------------------
 From: "Linda Burnside" <li...@burnsidebiz.com>
Sent: Wednesday, January 30, 2013 3:09 PM
To: "cf-talk" <cf-talk@houseoffusion.com>
Subject: Coldfusion and Twitter4j

I am trying to work with java and Twitter using Twitter4j 
(http://twitter4j..org/).  

I got oAuth to work, and I was able to return a string that looks like JSON 
but isn't.  I am no JAVA programmer.  I can do something with the string 
that is returned, but I ran into a snag when I tried to parse it.  There 
are commas inside single quotes that coldfusion wants to treat like a 
delimiter.  I could parse the string if I knew how to regex and replace the 
commas that not inside the single quotes.  That would give a delimiter 
other than a comma for the twitter posts.  

Here is my code that I'm using to return my twitter posts: 

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

twitterFactory = createObject("java", 
"twitter4j.TwitterFactory").init(config);

twitter = twitterFactory.getInstance().getUserTimeline().toString();
</cfscript>

The string that it returns looks like this: 

Twitter looks like this:

[StatusJSONImpl{createdAt=Mon Jan 14 13:32:31 EST 2013, 
id=290889145251946496, text='Since I have been unemployed, I've been 
freelancing using http://t.co/6fVzx6UX. All of a sudden, I'm very busy. 
Hurray!', source='web', isTruncated=false, inReplyToStatusId=-1, 
inReplyToUserId=-1, isFavorited=false, inReplyToScreenName='null', 
geoLocation=null, place=null, retweetCount=0, isPossiblySensitive=false, 
contributorsIDs=[J@1a7d7e5, retweetedStatus=null, userMentionEntities=[], 
urlEntities=[URLEntityJSONImpl{url='http://t.co/6fVzx6UX', 
expandedURL='http://Guru.com', displayURL='Guru.com'}], hashtagEntities=[], 
mediaEntities=[], currentUserRetweetId=-1, user=UserJSONImpl{id=19300560, 
name='linda burnside', screenName='happy_2b', location='Canton, Ohio', 
description='nerd extraordinaire', isContributorsEnabled=false, 
profileImageUrl='http://a0.twimg.com/profile_images/618051004/lindas_lady_bu
g_normal.jpg', 
profileImageUrlHttps='https://si0.twimg.com/profile_images/618051004/lindas_
lady_bug_normal.jpg', url='null', isProtected=false, followersCount=10, 
status=null, profileBackgroundColor='B2DFDA', profileTextColor='333333', 
profileLinkColor='93A644', profileSidebarFillColor='FFFFFF', 
profileSidebarBorderColor='EEEEEE', profileUseBackgroundImage=true, 
showAllInlineMedia=false, friendsCount=3, createdAt=Wed Jan 21 13:48:21 EST 
2009, favouritesCount=0, utcOffset=-18000, timeZone='Eastern Time (US & 
Canada)', 
profileBackgroundImageUrl='http://a0.twimg.com/images/themes/theme13/bg.gif'
, 
profileBackgroundImageUrlHttps='https://si0.twimg.com/images/themes/theme13/
bg.gif', profileBackgroundTiled=false, lang='en', statusesCount=3, 
isGeoEnabled=false, isVerified=false, translator=false, listedCount=0, 
isFollowRequestSent=false}}, StatusJSONImpl{createdAt=Tue Jul 26 10:59:56 
EDT 2011, id=95870974125293568, text='I need a Magento expert local to 
Canton, Ohio. It's like looking for the lesser spotted Cobol programmer. 
Sigh.', source='web', isTruncated=false, inReplyToStatusId=-1, 
inReplyToUserId=-1, isFavorited=false, inReplyToScreenName='null', 
geoLocation=null, place=null, retweetCount=0, isPossiblySensitive=false, 
contributorsIDs=[J@4f2b6c, retweetedStatus=null, userMentionEntities=[], 
urlEntities=[], hashtagEntities=[], mediaEntities=[], 
currentUserRetweetId=-1, user=UserJSONImpl{id=19300560, name='linda 
burnside', screenName='happy_2b', location='Canton, Ohio', 
description='nerd extraordinaire', isContributorsEnabled=false, 
profileImageUrl='http://a0.twimg.com/profile_images/618051004/lindas_lady_bu
g_normal.jpg', 
profileImageUrlHttps='https://si0.twimg.com/profile_images/618051004/lindas_
lady_bug_normal.jpg', url='null', isProtected=false, followersCount=10, 
status=null, profileBackgroundColor='B2DFDA', profileTextColor='333333', 
profileLinkColor='93A644', profileSidebarFillColor='FFFFFF', 
profileSidebarBorderColor='EEEEEE', profileUseBackgroundImage=true, 
showAllInlineMedia=false, friendsCount=3, createdAt=Wed Jan 21 13:48:21 EST 
2009, favouritesCount=0, utcOffset=-18000, timeZone='Eastern Time (US & 
Canada)', 
profileBackgroundImageUrl='http://a0.twimg.com/images/themes/theme13/bg.gif'
, 
profileBackgroundImageUrlHttps='https://si0.twimg.com/images/themes/theme13/
bg.gif', profileBackgroundTiled=false, lang='en', statusesCount=3, 
isGeoEnabled=false, isVerified=false, translator=false, listedCount=0, 
isFollowRequestSent=false}}, StatusJSONImpl{createdAt=Sat Mar 27 10:46:15 
EDT 2010, id=11146533974, text='Werk ... Werk ... Werk ... Now if only I 
could spell.', source='web', isTruncated=false, inReplyToStatusId=-1, 
inReplyToUserId=-1, isFavorited=false, inReplyToScreenName='null', 
geoLocation=null, place=null, retweetCount=0, isPossiblySensitive=false, 
contributorsIDs=[J@1abdb4f, retweetedStatus=null, userMentionEntities=[], 
urlEntities=[], hashtagEntities=[], mediaEntities=[], 
currentUserRetweetId=-1, user=UserJSONImpl{id=19300560, name='linda 
burnside', screenName='happy_2b', location='Canton, Ohio', 
description='nerd extraordinaire', isContributorsEnabled=false, 
profileImageUrl='http://a0.twimg.com/profile_images/618051004/lindas_lady_bu
g_normal.jpg', 
profileImageUrlHttps='https://si0.twimg.com/profile_images/618051004/lindas_
lady_bug_normal.jpg', url='null', isProtected=false, followersCount=10, 
status=null, profileBackgroundColor='B2DFDA', profileTextColor='333333', 
profileLinkColor='93A644', profileSidebarFillColor='FFFFFF', 
profileSidebarBorderColor='EEEEEE', profileUseBackgroundImage=true, 
showAllInlineMedia=false, friendsCount=3, createdAt=Wed Jan 21 13:48:21 EST 
2009, favouritesCount=0, utcOffset=-18000, timeZone='Eastern Time (US & 
Canada)', 
profileBackgroundImageUrl='http://a0.twimg.com/images/themes/theme13/bg.gif'
, 
profileBackgroundImageUrlHttps='https://si0.twimg.com/images/themes/theme13/
bg.gif', profileBackgroundTiled=false, lang='en', statusesCount=3, 
isGeoEnabled=false, isVerified=false, translator=false, listedCount=0, 
isFollowRequestSent=false}}]

Can anyone help me with either a way to get JSON back using Twitter4J or a 
regex to replace the commas that are not inside the single quotes? 

Linda



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:354130
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm

Reply via email to