Handling AOL Journal Comments
Having demonstrated many key features of the AOL Journals API in my last post, this week I'll demonstrate a new capability of the AOL.Journals CFC project, handling comments.
The AOL Journals ColdFusion implementation we've been working with is not currently released as part of the AOL API project on RIAForge. However, a release date is close and I thought I'd take the opportunity to demonstrate the comment handling functionality provided for AOL blog entries.
Start off by downloading the pre-release code and extracting it to your web application root. Like many of the previous examples we've worked with, we'll be using an instance of the OpenAuth component instance stored in session memory. Use the code from Listing 1 below to create a new AOL Journals component instance, passing in an AOL screenname and an OpenAuth component instance. The code then gets the workspace for the screenname and dumps its contents to screen. The result of this is shown in Figure 1.
<!--- create a new Journals object ---> <cfset obj_aolJournals = CreateObject( "component", "AOL.Journals" ).init( "bricemason", session.obj_openAuth ) /> <!--- get the current workspace ---> <cfset st_workspace = obj_aolJournals.getWorkspace() /> <!--- dump the workspace ---> <cfdump var="#st_workspace#" />Listing 1 - Creating a Journals component instance, getting a workspace

Figure 1 - Journals workspace
Now that we see a workspace, which consists of a series of blogs owned by the target screenname, we can gain access to the entries for the given blog by using the getEntries method below.
<!--- get the entries for the "My Private Journal" blog ---> <cfset arr_blogEntries = obj_aolJournals.getEntries( st_workspace[ "My Private Journal" ].href ) /> <!--- dump the blog entries data structure ---> <cfdump var="#arr_blogEntries#" />
The data structure exposed by the getEntries method is shown below.
The My Private Journal contains a single entry which we may now use to gain access to the current comments for this entry, post a new comment, then see the results by dumping the comments again. This action is shown below with the original comments shown in Figure 3 and the new comments in Figure 4.
<!--- get the current comments for the first entry and dump them ---> <cfdump var="#obj_aolJournals.getComments( arr_blogEntries[1].commentURI )#" /> <!--- post a comment to the entry ---> <cfset obj_aolJournals.postComment( arr_blogEntries[1].postCommentURI, "My Comment", "Added by ColdFusion!" ) /> <!--- get the current comments which now contain the comment we posted and dump it ---> <cfset arr_comments = obj_aolJournals.getComments( arr_blogEntries[1].commentURI ) /> <cfdump var="#arr_comments#" />

Figure 3 - Original comments

Figure 4 - New comments
The Added by ColdFusion! comment is now populated as part of the comment entries and is listed as the first and most recent comment. To delete this, use the following code:
<!--- delete the first comment which is the most recent --->
<cfset obj_aolJournals.deleteComment( arr_comments[1].commentURI ) />
Resources
- bricemason's blog
- Login or register to post comments
