Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@guustnieuwenhuis
Created March 19, 2012 08:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guustnieuwenhuis/e84459d04cc78ad47781 to your computer and use it in GitHub Desktop.
Save guustnieuwenhuis/e84459d04cc78ad47781 to your computer and use it in GitHub Desktop.
ColdFusion connect to FaceBook to display wall
<cfparam name="URL.limit" default="3" >
<cfparam name="URL.offset" default="0" >
<cfset page = "" />
<cfset access_token = "" />
<cfoutput>
<cftry>
<cfhttp url="https://graph.facebook.com/#page#/posts?access_token=#access_token#&limit=#URL.limit#&offset=#URL.offset#"
result="httpResult" charset="utf-8" method="get"/>
<cfset postsData = deserializeJSON(httpResult.filecontent)/>
<cfset posts = postsData.data />
<cfloop array="#posts#" index="post">
<cfif StructKeyExists(post, "created_time")>
<cfset created_time = post.created_time>
<cfelse>
<cfset created_time = "">
</cfif>
<cfif StructKeyExists(post, "message")>
<cfset message = post.message>
<cfelse>
<cfif StructKeyExists(post, "story")>
<cfset message = post.story>
<cfelse>
<cfset message = "">
</cfif>
</cfif>
<cfif StructKeyExists(post, "link")>
<cfset link = post.link>
<cfelse>
<cfset link = "http://www.facebook.com/#page#/posts/#ListLast(post.id, '_')#">
</cfif>
<cfif StructKeyExists(post, "picture")>
<cfset picture = post.picture>
<cfelse>
<cfset picture = "">
</cfif>
<cfif StructKeyExists(post, "comments") AND StructKeyExists(post.comments, "count")>
<cfset commentsCount = post.comments.count>
<cfelse>
<cfset commentsCount = "0">
</cfif>
<cfif StructKeyExists(post, "likes") AND StructKeyExists(post.likes, "count")>
<cfset likesCount = post.likes.count>
<cfelse>
<cfset likesCount = "0">
</cfif>
<p>
#LSDateFormat(Left(created_time, 10), "dd-mm-yyyy")# #lsTimeFormat(Mid(created_time, 12, 8), "HH:mm")#
<br />
<a href="#link#" target="_blank">
#message#
</a>
<br />
<cfif StructKeyExists(post, "picture")>
<a href="#link#" title="#message#" target="_blank"><img src="#picture#" width="90" /></a>
</cfif>
<br />
<a href="http://www.facebook.com/#page#/posts/#ListLast(post.id, '_')#" target="_blank">Comments(#commentsCount#)</a>
<br />
<a href="http://www.facebook.com/#page#/posts/#ListLast(post.id, '_')#" target="_blank">Likes(#likesCount#)</a>
</p>
<hr />
</cfloop>
<ul style="display: inline; list-style: none;">
<cfif URL.offset gt 0>
<li class="navPrev">
<a href="?limit=#URL.limit#&offset=#URL.offset - URL.limit#">#chr(171)# previous</a>
</li>
</cfif>
<li class="navNext">
<a href="?limit=#URL.limit#&offset=#URL.offset + URL.limit#">next #chr(187)#</a></li>
</ul>
<cfcatch type="any">
<p>
<cfdump var="#cfcatch#" />
#LSDateFormat(Now(), "dd-mm-yyyy")# #lsTimeFormat(Now(), "HH:mm")#<br />
<a href="##">
Oh, sorry... I can't connect to Facebook
</a>
</p>
</cfcatch>
</cftry>
</cfoutput>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment