Saturday, March 22, 2014

Getting Caspio data out to share on Facebook

I've been building an Austin Happy Hours database using Caspio, coming across a not-new challenge where I want to pull data out of Caspio results to use elsewhere on the pages, in this case for Facebook sharing.

It's a special challenge with Facebook, because they want you to use of Open Graph metatags in the of pages to control things like the title, image, share url and description of your content. And while sharing services like AddThis and ShareThis have customization options for these, Facebook doesn't honor them because of this insistence on using og: tags. In other words, those services have the same challenge I do.

I first tried to set javascript variables in my Caspio results to use once the datapage has loaded, which I've used successfully for Google Maps, DocumentCloud and other APIs. While I could append the new metatag to the head using jQuery, Facebook wouldn't honor them. I think that's because Facebook had already processed that part of the page, but I could be wrong.

What ended up working is to include my venue title in the URL of my detail page, so I could then parse it out using PHP and then use to write the metatag when the page was processed. This only worked for me because:

  • We recently got access to publish projects on an PHP server. (We don't have access to any server-side processing from within our CMS.) Without the server-side processing, I'd be out of luck.
  • The page where I wanted this was a Detail report form Caspio, which is drawn when I pass a parameter through the URL into the detail datapage. If I was using a normal Search and Report page, I wouldn't have the content I need in the URL.

There is a downside to this, in that my URL is really long, especially for Twitter. AddThis doesn't use a shortener (at least in their free service.) I started this project using ShareThis, who shortens the url for Twitter, but the ShareThis code was so slow loading I ended up abandoning it for AddThis.

Here are some of the details. I suspect my code is brutish, especially where I search and replace for things like commas, etc. That will break when I get a character I don't expect. I bet there is a PHP command that would do that for me? Please comment if you have a suggestion on that.


  © Blogger template 'A Click Apart' by 2008

Back to TOP