Hello,
the API call pwg.categories.getImages allows to insert (random) images into arbitrary websites. This works fine for me, but - as far as I see - only if the images are publicly accessible.
What do I have to do for this scenario: I want to decorate a choir website with 3 or 4 randomly changing images from our Piwigo photo gallery, but I do not want to give access for everybody to all of the thousands images in one go. In Piwigo I therefore set the access right to the images to "private" and allow only a certain technical user.
pwg.session.login and pwg.session.getStatus create a pwg_token, but how can I use this in pwg.categories.getImages?
Piwigo version: 2.9.2
PHP version: 5.5.9-1ubuntu4.22
MySQL version: 5.5.58-0ubuntu0.14.04.1
Thank you very much for the work you have already spent for Piwigo and for the work you will spend in future!
Till
Offline
Hello again,
no answers ...? Does this mean there is no way to get the private images? Or does it mean somebody is thinking? Or does it mean I should give more information?
Best regards,
Till
Offline
Hello,
I have the same problem as you described... Did you find a solution for this in the meantime?
Best regards!
Offline
Hello anni194,
unfortunately I do not have a solution, but I am still interested.
Regards,
Till
Offline
Hello !
I had the same problem and so I wrote a little function that enable to get images with the API for private albums. I know this topic is old but I'm sure it will be usefull for others.
Here are the steps (works only for a PHP site but you can adapt the code if needed) :
1. Create a new account on your Piwigo site and give it access on the album you want to use.
2. Add the following PHP function to your PHP site :
function getPictures($album_id, $element_per_page, $piwigo_API, $piwigo_user_login, $piwigo_user_pwd) { $res = null; //Login $loginData = http_build_query( array( 'method' => 'pwg.session.login', 'username' => $piwigo_user_login, 'password' => $piwigo_user_pwd ) ); $loginOpts = array('http' => array( 'method' => 'POST', 'header' => 'Content-Type: application/x-www-form-urlencoded', 'content' => $loginData ) ); $loginContext = stream_context_create($loginOpts); $login = file_get_contents($piwigo_API . '?format=json', false, $loginContext); //Get session id in cookie $loginID = ''; $cookies = array(); foreach ($http_response_header as $hdr) { if (preg_match('/Set-Cookie:\s*pwg_id=([\w]+);/', $hdr, $matches)) { array_push($cookies, $matches[1]); } } $loginID = $cookies[0]; //Get pictures $responseOpts = array('http' => array( 'method' => 'GET', 'header' => 'Cookie: pwg_id=' . $loginID ) ); $responseContext = stream_context_create($responseOpts); $response = file_get_contents($piwigo_API . '?format=json&method=pwg.categories.getImages&order=name&cat_id=' . $album_id . '&per_page=' . $element_per_page, false, $responseContext); $res = json_decode($response); //Logout $logoutOpts = array('http' => array( 'method' => 'GET', 'header' => 'Cookie: pwg_id=' . $loginID ) ); $logoutContext = stream_context_create($logoutOpts); $logout = file_get_contents($piwigo_API . '?format=json&method=pwg.session.logout', false, $logoutContext); return $res; }
3. Call the function "getPictures" (described on step 2) in your PHP site with the 5 following parameters :
-> The ID of the album
-> Number of images you want to get
-> URL of your API (ending with "/ws.php")
-> Login of the user you created on step 1
-> Password of the user you created on step 1
I know this can be improved but it's a good start for those who wants to get private pictures with API :) .
Enjoy ! ;)
Offline