Announcement

#1 2013-01-08 18:08:05

mcl
Member
2012-11-22
30

API I have done something wrong

I am using piwigo.com

I have tried using the API and I have managed to get some information back, but I seem to have done something stupid with regard to Tags, as the command I am using is returning.

Code:

array(3) { ["stat"]=> string(4) "fail" ["err"]=> int(401) ["message"]=> string(13) "Access denied" }

I probably do not understand the curl functions correctly as the remote call executes fine as a browser url
The first two curl requests work OK, it is the third one in the function getTags()

Code:

<?php

function getTags ($session) {
curl_setopt($session, CURLOPT_URL, 'http://mysite.piwigo.com/ws.php?format=php&method=pwg.tags.getAdminList');
curl_setopt($session, CURLOPT_HEADER, 0);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($session);
$response = unserialize($response);
varDump($response,"Get.Tags.Admin");


}
function varDump($r, $msg) {
  echo '<h3>' . $msg. '</h3>';;
  var_dump($r);
  echo '<hr>';

}
$session = curl_init();

curl_setopt($session, CURLOPT_URL, 'http://mysite.piwigo.com/ws.php?method=pwg.categories.getImages&format=php&recursive=true&order=random&f_with_thumbnail=true&per_page=1&page=0');
curl_setopt($session, CURLOPT_HEADER, 0);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($session);
$response = unserialize($response);
varDump($response,"Get.images.Random");

if ($response["stat"]=='ok')
{
  $picture_id = $response["result"]["images"]["_content"][0]['id'];
  
  curl_setopt($session, CURLOPT_URL, 'http://mysite.piwigo.com/ws.php?method=pwg.images.getInfo&format=php&image_id='.$picture_id);
  $response = curl_exec($session);
  $response = unserialize($response);
  varDump($response,"Get.image.Info");
  
  if ($response['stat']=='ok')
  {
    $picture = $response['result'];
    
// <a href="http://mysite.piwigo.com/picture.php?/'.$picture['id'].'"><img src="'.$picture['derivatives']['thumb']['url'].'" alt="'.$picture['name'].'" border="0" /></a></center>';
    echo '
<a href="http://mysite.piwigo.com/picture.php?/'.$picture['id'].'"><img src="'.$picture['derivatives']['square']['url'].'" alt="'.$picture['name'].'" border="3" width="80px" /></a></center>';
echo '<a href="'. $picture['derivatives']['medium']['url'] . '"><img src="'.$picture['derivatives']['square']['url'].'" alt="'.$picture['name'].'" border="3" width="80px" /></a></center>';
  }
}

getTags($session);
curl_close($session);

?>

Any pointers to what I have done wrong / misunderstood would be appreciated

Offline

 

#2 2013-01-08 19:43:07

mistic100
Former Piwigo Team
Lyon (FR)
2008-09-27
3277

Re: API I have done something wrong

I think you must login first, with the method pwg.session.login (as pwg.tags.getAdminList is an admin only method)

Offline

 

#3 2013-01-08 21:17:51

mcl
Member
2012-11-22
30

Re: API I have done something wrong

Hi There,

Many thanks for your help.

It worked, but you must use POST method.

mcl

Offline

 

#4 2013-01-08 21:24:40

mistic100
Former Piwigo Team
Lyon (FR)
2008-09-27
3277

Re: API I have done something wrong

as written in tools/ws.htm yes :)

Offline

 

Board footer

Powered by FluxBB

github twitter newsletter Donate Piwigo.org © 2002-2024 · Contact