123RF Value Added Reseller – Display Specific Content Details (Part 3 of 5)

 

This time around, we will be using looking at the description, keywords and larger size comping image for a specific 123RF Content ID.

About the GetInfo API

123RF’s GetInfo API (123rf.images.getInfo.V2) supports the following arguments.

getInfoAPI

This API call requires only 2 pieces of information to work, the content ID as well as the language. And if you are choosing English, you need not even supply this argument.

Step 1: Passing the Parameter and Value

In this example, we will just append a simple parameter and value to the script that we will create. Using the information, we will then get the API to furnish us with the XML that will enable us to display more information on the image.

The parameters passed will be imageID and language.

Say for example we are interested in this image’s details: http://www.123rf.com/photo_7362823_couple-relaxing-at-the-tip-of-the-yacht.html

The Image ID is 7362823. The language we are interested in is English.

Therefore, our parameter string will look like this: ?imageid=7362823&language=en

Step 2: Processing the Parameters Passed to the Script and Constructing the API call

The script has to start constructing the URL that will be used in the API call. This is done by passing the image ID and appending it into the API call URL string directly. No special URLencode function is required at this point.

<?php

// constants

$apikey = "fd022e333ae6ac4aa56ed1c3221cfb2c";

// extract arguments from $_GET

$imageid = $_GET['imageid'];
$language = $_GET['language'];

// construct the URL required for the API call

$theURL = "http://api.123rf.com/rest/?method=123rf.images.getInfo.V2&apikey=".$apikey.
          "&imageid=".$imageid.
          "&language=".$language;
?>

Step 3 : Execute the API call and then display the results accordingly

Here we execute the API call and then we can display the larger comp image. To display the comp image, please refer to the documentation here: Comping, but it’s actually very simple, all URL to thumbnails take on this structure: http://images.assetsdelivery.com/compings/[contributorid]/[folder]/[filename].jpg

<?php

// Execute the API call and store into a variable

$contents = file_get_contents($theURL);

// Declare this as a new SimpleXmlElement

$xml = new SimpleXmlElement($contents);

// retrieve the information specific to the image

  $id = (string) $xml->image[id];
  $dateuploaded = (string) $xml->image[dateuploaded];
  $filename = (string) $xml->image[filename];
  $folder = (string) $xml->image[folder];
  $contributorid = (string) $xml->image->contributor[id];
  $desc = $xml->image->description;

// construct the comping image URL

  $compimg = "http://images.assetsdelivery.com/compings/$contributorid/$folder/$filename.jpg";

// Store all keywords into a variable and step through it to get all keywords into an array

  $keywords = $xml->image->keywords->keyword; 

  foreach ($keywords AS $kw){
  $keywordArr[$x++] = (string) $kw;
  }

// Implode the keywords so that it looks like a normal string

  $keywordsTxt = implode (", ", $keywordArr);
// Output the content's details for preview
echo <<< ___
<h1>$desc</h1>
<img src="$compimg">
<p>Keywords:<br />
$keywordsTxt
</p>
___;

?>

You can enhance your script with code that makes the user experience better, but the above is the absolute minimum to get things working. Visit a demo of the 123RF GetInfo API in action, or download the script above and experiment with it. Please note you will have to insert your own API key into the script to get it to work!

Recommend this story :
Back to Top ↑

Leave a Reply

Your email address will not be published. Required fields are marked *

Show Buttons
Hide Buttons