With this method you can retrieve messages from a Twitter user.

<!--- Twitter user used by the system --->
<cfparam name="userTwitter" default="">
<!--- password from Twitter user used by the system --->
<cfparam name="passTwitter" default="">
<!--- login to Twitter friend we want to recover the messages --->
<cfparam name="friendTwitter" default="">
<cfif Len(Trim(friendTwitter))>
    <!--- Object used in this page --->
    <cfset twitter = CreateObject('component','org.cftwitterlib.Twitter').init(userTwitter,passTwitter)>
    <!--- start the variable to be passed as parameter --->
    <cfset options = StructNew() >
    <!--- login to Twitter friend --->
    <cfset options['screen_name'] = friendTwitter >
    <!--- number of messages per page --->
    <cfset options['count'] = 10 >
    <!--- number of page --->
    <cfset options['page'] = 1 >
    <!--- recover the messages --->
    <cfset timeline = deserializeJSON(twitter.getUserTimeline(options).toString()) >
    <!--- messages exists --->
    <cfif IsArray(timeline)>
        <cfoutput>
            <!--- displays each message's friend --->
            <cfloop from="1" to="#ArrayLen(timeline)#" index="i">
        <div style="border:1px solid ##000; padding:5px; width:350px;">
            <dl style="margin:0">
                <dt style="margin:0">
                    <!--- if the friend sent the message in response, retrieves and displays the original message --->
                    <cfif timeline[i].in_reply_to_status_id neq "null">
                        <cfset currentMsg = deserializeJSON(twitter.getStatus(timeline[i].in_reply_to_status_id).toString())>
                        <div>
                            <img src="#currentMsg.user.profile_image_url#" height="20" />
                            <a name="message_#currentMsg.id#"></a>
                            <cfif currentMsg.favorited> <img src="images/cool.gif" /></cfif>
                            #DateFormat(currentMsg.created_at,'dd-mm-yyyy')# #timeFormat(currentMsg.created_at,'hh:mm:ss')#
                            -
                            #currentMsg.text#                    
                        </div>
                    </cfif></dt>
                <dd style="margin:0; <cfif Len(Trim(timeline[i].in_reply_to_status_id))>margin-left:10px</cfif>"><img src="#timeline[i].user.profile_image_url#" height="20" />
                            <a name="message_#timeline[i].id#"></a>
                            <cfif timeline[i].favorited> <img src="images/cool.gif" /></cfif>
                            #DateFormat(timeline[i].created_at,'dd-mm-yyyy')# #timeFormat(timeline[i].created_at,'hh:mm:ss')#
                            -
                            #timeline[i].text#</dd>
                    </dl>
                </div>        
            </cfloop>
        </cfoutput>
    <cfelse>
        <!--- the limit of request on account is 100 --->
        Rate limit exceeded.
    </cfif>
</cfif>

public string getUserTimeline(struct options, [string format])

options = Data structure containing the options you want, at least the id or screen_name or user_id should be passed.

options.id = identifier of the user in Twitter (different from login)

options.user_id = identifier of the user in Twitter (different from login)

options.screen_name = name (login) of user in Twitter

options.since_id = identifier of the user in Twitter (different from login)

options.page = number of current page

options.count = number of messages per page

format (opcional, json is default) = xml, json, rss, atom

Related Blog Entries

TrackBacks
There are no trackbacks for this entry.

Trackback URL for this entry:
http://blog.pcsilva.com/en/trackback.cfm?CF5D3424-C292-0404-09DCCA354FDE89CD

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)