Ping.fm + Custom URL = mobile photo blog

Yeah, get that? Remember when I wrote an ugly little script that allowed for posting to a mobile photo blog from my sprint phone? Yeah, it was really ugly but it worked... sometimes.

It was a fun exercise but sometimes you gotta step aside and let the pros do the heavy lifting. That's where ping.fm comes in. The problem with my original script was too many points of failure. If the photo couldn't be scraped, fail. If cfpop timed out, fail. If the script timed out, fail. It was a script I wrote quickly (and I'll admit, poorly). In retrospect what I should have done is scraped the photo, the message, subject etc and only after all of that was successful, pass it to another template that handled inserting the content. Moot point now.

Good news! That's what the Custom URL does with ping.fm. It takes your content, in my case a photo along with a message and title, and it passes the data to any URL of my choosing. All you need is a script that waits for this data and does all of the juicy processing. Here's how I set mine up:

Summary

Add Custom URL as a "Network"

Add Custom URL

Add custom URL as a network and head to http://ping.fm/custom/, which I think you'll be taken to as part of the setup process.

Customize Custom URL

Setup Custom URL

Now you'll want to fill in the URL to your custom URL. I'd put it somewhere tucked away where it wont be found.

You'll see in my example screenshot above I picked the Blogging method. I did that because I need to pass a subject along with the pic and message. The Blogging method at ping.fm is the only method where you can pass the subject along with your message. (someone correct me if I'm wrong). I'm using the subject to build the URL where the entry will end up. That's sort of off track but wanted to explain why I picked that and not the other methods.

Add Custom Trigger

I set up a custom trigger to hit the custom URL every time I post to that trigger. I did this because I don't want ping posting to this custom URL every time I make a post to twitter or facebook, etc. By using a custom trigger I can tell ping.fm exactly when I want the data posted to my custom URL, easy right?

Add Trigger Add Custom URL

One more thing, here's a list of POST variables ping.fm will pass to the custom URL, you can see a more in-depth description on the ping.fm google group.

  • method - The method of the message being sent (blog, microblog, status).
  • title - If method is "blog" then this contain the blog's title.
  • message - The posted message content.
  • location - Any location updates posted with the message. This is plaintext, verbatim from the posting interface.
  • media - If media is posted, this will contain a URL to the media file.
  • raw_message - If media is posted, this will contain the posted message WITHOUT the hosted media link (i.e. http://ping.fm/p/12345)
  • trigger - If you post a message with a custom trigger (http://ping.fm/triggers/), it will show here.

Juicy Script

I have a bunch of fancy stuff going on like creating a log file every time the URL is hit, dumping the POST variables some other fancy stuff that I'm going to strip out to keep this simple.

<!--- set up the parameters --->
<cfparam name="FORM.METHOD" default="" type="string">
<cfparam name="FORM.TITLE" default="" type="string">
<cfparam name="FORM.MESSAGE" default="" type="string">
<cfparam name="FORM.RAW_MESSAGE" default="" type="string">
<cfparam name="FORM.LOCATION" default="" type="string">
<cfparam name="FORM.MEDIA" default="" type="string">
<cfparam name="FORM.TRIGGER" default="MO" type="string">

<!--- I use my single custom URL for many different things, 
so I'm going to do a switch through the trigger to determine the action --->
<cfswitch expression="#FORM.TRIGGER#">

	<!--- mophoblog --->
	<cfcase value="MO">
	   
	   <!--- make sure I remembered to attach the image (from my phone) and I format the message w/ a title --->
		<cfif Len(FORM.MEDIA) AND Len(FORM.TITLE)>
			
		<!--- get the image --->
		<cfhttp url="#FORM.MEDIA#" 
			method="GET" 
			getasbinary="yes" 
			result="objHttp">
		</cfhttp>
		
			<!--- if the image was found --->
			<cfif (FindNoCase("200",objHttp.Statuscode) AND FindNoCase("image",objHttp.Responseheader["Content-Type"]))>				
				
				<!--- make up some gangster long file name --->
				<cfset fileName = Hash(Timeformat(Now(),"Long"))>
				
				<!--- save it locally --->
				<cfimage source="#objHttp.FileContent#" 
					action="write" 
					isBase64="yes" 
					destination="#destination#\#fileName#.jpg" 
					overwrite="true">
					
				<!--- scale it down --->
				<cfimage action="resize"
					height="" 
					width="640" 
					source="#destination#\#fileName#.jpg" 
					destination = "#destination#\#fileName#.jpg" 
					overwrite="true">
					
				<!--- make a thumbnail --->
				<cfimage action="resize" 
						name="thumbnail"
						height="150"
						width=""
						source="#destination#\#fileName#.jpg" 
						destination="#destination#\#fileName#-thumb.jpg" 
						overwrite="yes">								
			
				Add it to the database
				Utilize the ping API to send a message to microblogging
				Or do a simple <cfmail> and post back to ping using your posting address
			
			</cfif>
		
		</cfif>
	
	</cfcase>
	
	<!--- blog --->
	<cfcase value="BL">
		Do blog stuff
	</cfcase>
	
	<!--- tumblr --->
	<cfcase value="TM">
		Do Tumblr stuff
	<cfcase>
	
	<!--- Anything you want to do --->
	<cfcase value="LL">
		Send my wife a love letter
	</cfcase>
	
</cfswitch>

The code is pretty well commented and very straight forward. Ping.fm passes any custom triggers you used during that post. That means you can easily use the trigger as a hook as I did in my example script. This makes the possibilities virtually unlimited. The example script locates the correct trigger, in this case #MO, checks to make sure the title and media is present, makes an http request for the image, saves it locally and creates the mophoblog entry.

From the user standpoint (that's me), I take a photo with my phone, send the photo along with a message to my Ping.fm posting address. That's it, nothing more. It's posted to my blog in literally a minute or two. Here is how I format the message.

#CustomTriggerName Title Of Blog Entry^Body of blog entry.

So on this particular mophoblog entry I sent:

	#MO Jacks Vaccine^a stark contrast from last time we were here	

Note that if you pick another method, either status or microblogging you don't need the special "title^body" formatting. I do that because I take the title and make it the URL for my mophoblog entry.

In Closing

I hope, although you may not understand Coldfusion, you are able to see the possibilities of such a simple yet powerful feature of ping.fm. No other service that I know of allows you to pass data like this so freely. No dealing with a messy API, this is a simple script. I'm sure as more developers catch wind of this the more sample scripts will start to surface. Don't forget to check out the google group for a good php sample.

*edit

To show off my GIMP skeels I made this fancy diagram.

Ping Diagram

Comments    

11.27.2008   Brandner
Hey, great post! I'm a CF developer (over 10 years now), and this post helped me put together a custom URL script in a minute or two. Thanks!

T
11.27.2008   jyoseph
Good to hear Brandner! It's pretty simple once you get it all set up. Ping away!
11.27.2008   jyoseph
Just realized how horrible the code formatting turned out in IE, sorry folks.
11.27.2008   Chris W.
I told you man. I told you.

Leave One

  • Required fields are marked with an asterisk *

Tags
Share
Back Up   |   Blog Feed