This is a basic PHP package allowing you to log in, browse albums, search for photos and download high resultation images in a way that recembles our current image archive. It's ment as an inspiration on what you can do with our API or a quick way to get you started.
Download the quck start
< ?php
/*
* Settings
* /
$baseurl = 'https://api.bildbyran.se/v1/';
$apikey = 'xxx';
/*
* Basic data fetch function
* $req = data-array, ex array('limit' => $limit,'offset' => $offset);
* $url = api-endpoint, ex latest/albums (no starting or trailing slash)
* $raw = true/false to enable or disable raw JSON instead of a php-array (ex $raw = 'true' for JSON)
*/
function getData($req, $url,$raw) {
$url = $GLOBALS['baseurl'].$url.'?'.$req.'&apikey='.$GLOBALS['apikey'];
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
curl_close($ch);
if(!$raw) return json_decode($result, true); else return $result;
}
/*
* Example functions returning endpoint specific data using getData()
*/
function getAlbumList($limit, $offset) {
$url = 'albums';
$req = 'limit='.$limit.'&offset='.$offset;
return getData($req, $url,$raw);
}
function getLatestImages($limit, $offset) {
$url = 'photos';
$req = 'limit='.$limit.'&offset='.$offset;
return getData($req, $url,$raw);
}
function getPopularImages($limit, $offset,$days) {
$url = 'photos';
$req = 'limit='.$limit.'&offset='.$offset.'&days='.$days.'&sorting=popularity';
return getData($req, $url,$raw);
}
function getImage($id,$size) {
$url = 'photos/'.$id.'/thumbnail';
$req = 'size='.$size;
return getData($req, $url,'true');
}
function downloadImage($id,$size) {
$url = 'photos/'.$id.'/download';
$req = 'size='.$size;
return getData($req, $url,'true');
}
function getImageCaption($id) {
$url = 'photos/'.$id.'/';
$req = '';
return getData($req, $url,$raw);
}
function getSearchResults($q,$limit,$offset) {
$url = 'photos';
$req = 'limit='.$limit.'&offset='.$offset.'&q='.$q;
return getData($req, $url,$raw);
}
? >