Mauro Pirrone | Blog

Design & Logic Arts

Web Services

Posted in Web Design by Mauro on the June 6th, 2008

A web service is a software program identified by a URI which can be accessed through internet. It consists of well-defined, re-usable, software components that perform specific, encapsulated tasks via standardised web-oriented mechanisms.

Web services can be used with any programming language such as PHP or ASP.NET. With little code and some XML, you can include some of Google’s or Yahoo’s functionality in your own website!

But what’s exactly XML? XML is simply a mark-up language that defines other languages and protocols:

  • WSDL - Web Service Description Language
  • UDDI - Universal Description, Discovery and Integration
  • SOAP – Simple Object Access Protocol


Image courtesy of Wikipedia

If you are new to XML, I suggest taking a tutorial here.

In PHP it is very easy to use a web service. It’s a matter of few lines of code!
http://www.php.net/soap_soapclient_soapcall

And one last thing…here are a list of web services which you might use in your website or web app.
http://www.programmableweb.com/apis/directory/1?sort=mashups

In the near future I will be publishing an article how you can create an ajaxed site search using a web service. As always, feel free to send your comments!

Integrating Flickr with your PHP website

Posted in Web Design, Web Development by Mauro on the May 31st, 2008

Flickr is an image and video hosting website. Luckily enough, they provide a web service to access your photos and use them in any way you want. To get you into perspective, here’s the Flickr photoset which I am using, and here are the customised photo gallaries which I created using PHP:

Although I’m showing you how to integrate Flickr with Lightbox and PostCardViewer, this technique works with any photo gallery including the commercial one SlideShowPro.

Step 1

Downlaod the phpFlicker library from http://phpflickr.com/

Download Lightbox or PostCardViewer (or any other photo gallery).

Step 2

To access Flickr using a web service, you need an API key. You may get one from http://www.flickr.com/services/api/keys

Step 3

Get the photoset ID. In this case I am using photoset id ‘72157605353756648′. Note that the photoset id is part of the URL. For example, http://www.flickr.com/photos/26262208@N07/sets/72157605353756648/

Step 3

Step up your php script.

require_once("phpFlickr/phpFlickr.php");
$f = new phpFlickr("your api key");
$photoset_id = '72157605353756648';
$photos = $f->photosets_getPhotos($photoset_id);

Step 4

Loop through each photo in the photoset and you’re done! The following example uses the Lightbox photo gallery.

<ul>
<?php foreach ($photos['photo'] as $photo): ?>
<li><a rel="lightbox[roadtrip]" href="<?= $f->buildPhotoURL($photo, ‘medium’) ?>" title="<?= $photo['title'] ?>"><img src="<?= $f->buildPhotoURL($photo, ’square’) ?>" alt="<?= $photo['title'] ?>" title="<?= $photo['title'] ?>" /></a></li>
<?php endforeach; ?>
</ul>

Notes

  • You may easily change the file size by specifying either square, thumbnail, small, medium, large or original. For example: $f->buildPhotoURL($photo, ‘large’)
  • You may programmatically get the photoset ids by using the API call photoset.getList (or photoset_getList method)
  • You may also use API calls to get comments, upload photos, and so on
  • For the complete API documentation visit here

Source Code Download