Flickr Services
The App Garden
Serialized PHP Response Format
PHP has a built-in serialized data structure format, using the serialize()
and unserialize()
functions.
To return an API response in PHP serialized format, send a parameter "format
" in the request with a value of "php_serial
".
The returned data structures match the JSON response structures - please read the JSON documentation for further details.
To perform a very simple request in PHP 5, your code might look like this:
#
# build the API URL to call
#
$params = array(
'api_key' => '81e7e11aeac57ac668609d316f6388ce',
'method' => 'flickr.photos.getInfo',
'photo_id' => '251875545',
'format' => 'php_serial',
);
$encoded_params = array();
foreach ($params as $k => $v){
$encoded_params[] = urlencode($k).'='.urlencode($v);
}
#
# call the API and decode the response
#
$url = "http://http://www.zjjv.com///services/rest/?".implode('&', $encoded_params);
$rsp = file_get_contents($url);
$rsp_obj = unserialize($rsp);
#
# display the photo title (or an error if it failed)
#
if ($rsp_obj['stat'] == 'ok'){
$photo_title = $rsp_obj['photo']['title']['_content'];
echo "Title is $photo_title!";
}else{
echo "Call failed!";
}
Examples
You can see a successful serialized PHP response here.
You can see a serialized PHP failure response here.
0
0