I am trying to pull some data from our Twitter feed and display it in the browser using ColdFusion and the Twitter API.
Here is my code:
<!--- GET Twitter Feed --->
<cfhttp url = "https://api.twitter.com/1/statuses/user_timeline.json?screen_name=OurTwitterFeed" getAsBinary="never">
<!--- Create variable and assign file contents --->
<cfset twitterData = #cfhttp.FileContent#>
<!--- Check if file is valid JSON - If so, deserialize --->
<cfif !IsJson(twitterData)>
<h3>Not Valid JSON</h3>
<cfdump var="#cfhttp.FileContent#">
<cfelse>
<cfset cftwitterData = DeserializeJSON(twitterData)>
</cfif>
<!--- Find columns in the array. --->
<cfset colList=ArrayToList(cfTwitterData.COLUMNS)>
<cfset textIdx=ListFind(colList, "text")>
<cfset sourceIdx=ListFind(colList, "source")>
<cfset dateIdx=ListFind(colList, "created_at")>
<!--- Loop thru and display the DATA from the array --->
<cfoutput>
<cfloop index="j" from="1" to="#ArrayLen(cfTwitterData.DATA)#">
<h3>My Tweets</h3>
Date: #cfTwitterData.DATA[j][dateIdx]#<br>
Tweet: #cfTwitterData.DATA[j][textIdx]#<br>
URL/Source: #cfTwitterData.DATA[j][sourceIdx]#
</cfloop>
</cfoutput>
Apparently it doesn't like my ArrayToList function because I get the following error message when I try to run the code. :
You have attempted to dereference a scalar variable of type class coldfusion.runtime.Array as a structure with members.
When I dump the data it is in an array of structures. How can I deserialize the json and display it as text on the screen?