Announcement

  •  » Extensions
  •  » Piwigo webapi - pwg.categories.getList bugs?

#1 2016-05-28 16:26:49

eliz82
Member
Romania
2016-04-27
265

Piwigo webapi - pwg.categories.getList bugs?

Hello,
I'm trying to work with Piwigo Web api method "pwg.categories.getList" and it give me headaches writing some code.

For example if category has sub-categories "tree_output" parameter work ok:

1) http://piwigo.org/demo/ws.php?format=re … tput=false
tree_output=false ... work ok

2) http://piwigo.org/demo/ws.php?format=re … utput=true
tree_output=true ... work ok
---
But if category do not have any sub-categories then "tree_output" parameter can return an error notice

1) http://piwigo.org/demo/ws.php?format=re … tput=false
tree_output=false ... work ok

2) http://piwigo.org/demo/ws.php?format=re … utput=true
tree_output=true ... do not work ... give error notice

If you ask me this is not normal. tree_output=true  should give an response if that category do not have sub-categories, not an error.

P.S.  PHP output have the same problem like the REST output

Last edited by eliz82 (2016-05-29 21:25:42)

Offline

 

#2 2016-05-28 19:52:30

eliz82
Member
Romania
2016-04-27
265

Re: Piwigo webapi - pwg.categories.getList bugs?

another problem that i encounter with "pwg.categories.getList"

if you request any cat_id except 0, then that category id is included in the response. will be the first element in the response. example:
http://piwigo.org/demo/ws.php?format=re … cat_id=112

if you request the cat_id 0 (the root), then that category id is not included in the response. the response (the array in the PHP method) is containing one element less. example:
http://piwigo.org/demo/ws.php?format=re … p;cat_id=0

my opinion is that "&cat_id=0" should give the same type of response as the rest of categories.
otherwise you will force your webapi developers to write some workaround code.

Last edited by eliz82 (2016-05-28 20:03:30)

Offline

 

#3 2016-05-29 18:29:01

eliz82
Member
Romania
2016-04-27
265

Re: Piwigo webapi - pwg.categories.getList bugs?

another problem i encounter
"pwg.categories.getList" and "pwg.categories.getImages" seem to give sometime different responses when ask the same thing

for example if you want to check the total number of pictures a category has:

1) example using pwg.categories.getList:
http://demo.piwigo.com/ws.php?format=re … p;cat_id=3

this return 74 total images in category 3:

<category id="3" status="public" nb_images="0" total_nb_images="74" ...>

2) example using pwg.categories.getImages:
http://demo.piwigo.com/ws.php?format=re … rsive=true

this return 69 total images in category 3:

<paging page="0" per_page="100" count="69" />

--------
seems the "pwg.categories.getList" will count the same picture multiple times in recursive mode, if that picture has been added to multiple sub-categories. this will falsely count the total number of pictures from that category.

so "pwg.categories.getList" is unreliable for counting the total number of unique pictures in a category.

"pwg.categories.getImages" is reliable for counting only if that category has less then 500 pictures. (this is the piwigo pwg.categories.getImages default max limit).
we can resolve this making a loop asking 500 pictures and using "&page" parameter but this will generate large amount of data. lets presume that category has 15000 images and is on another server. we need to request 30 responses from other server, each response array will have 500 keys. big amount of network data and cpu processing for such a banal task. if you ask me this is unusable.
--------
so let me explain the problem i have because of this:

so let presume we are using web api to list the pictures recursively from a category that has total_nb_images="15000" but the real number of pictures are 14000 (because 1000 pictures are in 2 categories).
trying to calculate the number of pages to list using "pwg.categories.getImages" & page parameter will result in:
15000 / 500 (per page) => 30 pages.
so i will show in my program 0...29 pages numbers to click.

when trying to list the pictures using pwg.categories.getImages&recursive=true&page=29 (or 28,27) your api will give an empty response. the &page=27 will be the last that list pictures (because the pictures are 14000).

---------
how this should work to be usable ?

pwg.categories.getList&recursive should have another parameter that return the unique number of pictures.

in this way we can use "total_unique_nb_images" to correctly calculate the number of pages on a category that has subcategories with pictures added in multiple categories.

we will use "total_nb_images" if that categories do not have subcategories , but it has pictures that are in multiple categories.

we already can use "nb_categories" to check is a category has subcategories. so we can use this kind of code

Code:

if ($api_array['nb_categories']>0) {
    $total_pictures = $api_array['total_unique_nb_images']; //using the new parameter
}
else {
    $total_pictures = $api_array['total_nb_images']; //using the old parameter
}
$pages =   $total_pictures/$pictures_per_page;

now we can use $pages with "pwg.categories.getImages&recursive=true&page=..." as this kind of logic will generate correct data

Last edited by eliz82 (2016-08-18 07:38:36)

Offline

 

#4 2016-10-29 18:16:42

eliz82
Member
Romania
2016-04-27
265

Re: Piwigo webapi - pwg.categories.getList bugs?

Piwigo Web Api JSON output should send header with CORS enabled by default, for easy access with javascript:

Code:

header('Access-Control-Allow-Origin: *');

... like Zenphoto REST Api does
[Github] zenphoto-json-rest-api file json_rest_api.php

The majority of servers dont have CORS enabled by default
http://piwigo.org/forum/viewtopic.php?p … 78#p163178

Last edited by eliz82 (2017-09-27 06:50:41)

Offline

 

#5 2017-10-08 09:34:22

nicolas
Former Piwigo Team
2004-12-30
1187

Re: Piwigo webapi - pwg.categories.getList bugs?

eliz82 wrote:

Piwigo Web Api JSON output should send header with CORS enabled by default, for easy access with javascript:

Code:

header('Access-Control-Allow-Origin: *');

That means no check at all. Are you sure that is a good idea ?

Offline

 

#6 2017-10-08 19:19:51

eliz82
Member
Romania
2016-04-27
265

Re: Piwigo webapi - pwg.categories.getList bugs?

Why ... is some sort of security breach behind this? Do not forget that I'm requesting this header only for json response (not for the entire software). It even be more strict and have this header only for api methods that only read the database (not write).

I really see no point to complicate developers life. For example PiwigoMedia uses Php the get the json data, then transfer it to Javascript. I would prefer to get the data for remote sites directly with Javascript, to not use two programing languages for this.

Offline

 
  •  » Extensions
  •  » Piwigo webapi - pwg.categories.getList bugs?

Board footer

Powered by FluxBB

github twitter facebook google+ newsletter Donate Piwigo.org © 2002-2020 · Contact