samwilson / phpflickr

A PHP wrapper for the Flickr API, including OAuth.
https://packagist.org/packages/samwilson/phpflickr
GNU General Public License v2.0
40 stars 15 forks source link

Getting photos within sets #5

Open MartinKlefas opened 6 years ago

MartinKlefas commented 6 years ago

I've used this fork to replace the outdated version of phpFlickr that was coded into flogr (https://github.com/mcarruth/flogr) and it seems to work really well - thank you for all of the work that's gone into it. The only problem I'm having is that some changes must have happened so long ago that I'm struggling to trace them back!

Is getting the photos within a particular set something I'd need an OAuth token for? I can currently get a list of my sets, and their cover photos - so I don't think the issue is with the API Key or API Secret...

Thanks

samwilson commented 6 years ago

Thanks for trying out this fork! :) It's nice to know it's possibly of use.

I've not yet got to converting photosets.getPhotos to the new class layout, but the old style should work:

$phpFlickr->photosets_getPhotos(72657638907952846)

Do you get any error with that?

MartinKlefas commented 6 years ago

I don't seem to get any error or any results!

It's a bit tricky because it's all tied together inside the flogr wrappers, so I've had to add the line die(var_dump(PhpFlickr->photosets_getPhotos($photosetId)));

in the middle of the function that would usually be returning the set photos. There's also an error suppression part to flogr, and so I've had to change the error suppression from only reporting E_ERROR to E_WARNING - as commenting it out completely caused nothing to work and still no errors to be thrown!

Anyway, when I do all of that, the page just abruptly ends mid-way through, the last line in the html is a

tag, and nothing actually seems to die to the page...

It's been a while by the way - apologies if this was a daft way of getting the information we need - would it help if I shared the "Work In Progress" dropbox folder?

MartinKlefas commented 6 years ago

OK - so revisited this and started from scratch with a new project. Index.php ended up being as simple as:

$apiKey = '*****';
$apiSecret = '*****';

require_once 'vendor/autoload.php';
$flickr = new \Samwilson\PhpFlickr\PhpFlickr($apiKey, $apiSecret,true);

echo "<pre>";
#var_dump($flickr->photosets_getList('7394337@N06')); - originally here to check that the photo set ID was correct.
var_dump($flickr->photosets_getPhotos('72157638523485346'));

This results in outputting all the correct information for that particular set - but if I leave out the quote marks around the set ID it returns nothing. I figured maybe this was the problem I was having - the set IDs look like they're numbers - so I modified

public function photosets_getPhotos($photoset_id...

to

public function photosets_getPhotos(String $photoset_id

But then dumping out the photoset_id still gave me the "number-version" 7.2157638523485E+16 I'm at a loss as to how to correct this - but I'm not sure I'll need to...

Because I finally worked out what I was doing wrong in my post above! I changed the line added in the middle of the flogr function function get_set_photos to match the function return:

die(var_dump($this->PhpFlickr->photosets_getPhotos(
                $photosetId,
                $extras ? $extras : 'original_format,date_taken,date_upload',
                $privacyFliter,
                $perPage ? $perPage : $this->paramPerPage,
                $page ? $page : $this->paramPage)));

And this seems to dump out the photoset array in a seemingly suitable format, including an array of 98 photos (excerpt below). Has the results array changed in such a way that flogr might not be able to understand it in some way?

edit: This seems to be processed by the function: $this->PhpFlickr->buildPhotoURL($photo, "thumbnail") has this been implemented in such a way as to understand the "photo" arrays below?


array(2) {
--
  | ["photoset"]=>
  | array(11) {
  | ["id"]=>
  | string(17) "72157638523485346"
  | ["primary"]=>
  | string(11) "11296522014"
  | ["owner"]=>
  | string(11) "7394337@N06"
  | ["ownername"]=>
  | string(22) "Martin Klefas-Stennett"
  | ["photo"]=>
  | array(98) {
  | [0]=>
  | array(15) {
  | ["id"]=>
  | string(11) "11296522014"
  | ["secret"]=>
  | string(10) "982ce28b7f"
  | ["server"]=>
  | string(4) "5523"
  | ["farm"]=>
  | int(6)
  | ["title"]=>
  | string(8) "DSC_5553"
  | ["isprimary"]=>
  | string(1) "1"
  | ["ispublic"]=>
  | int(1)
  | ["isfriend"]=>
  | int(0)
  | ["isfamily"]=>
  | int(0)
  | ["dateupload"]=>
  | string(10) "1386623432"
  | ["datetaken"]=>
  | string(19) "2013-12-08 21:35:01"
  | ["datetakengranularity"]=>
  | string(1) "0"
  | ["datetakenunknown"]=>
  | int(0)
  | ["originalsecret"]=>
  | string(10) "5ef6ecd195"
  | ["originalformat"]=>
  | string(3) "jpg"
  | }
  | [1]=>
  | array(15) {
  | ["id"]=>
  | string(11) "11296561153"
  | ["secret"]=>
  | string(10) "09a2c92002"
  | ["server"]=>
  | string(4) "3759"
  | ["farm"]=>
  | int(4)
  | ["title"]=>
  | string(8) "DSC_5554"
  | ["isprimary"]=>
  | string(1) "0"
  | ["ispublic"]=>
  | int(1)
  | ["isfriend"]=>
  | int(0)
  | ["isfamily"]=>
  | int(0)
  | ["dateupload"]=>
  | string(10) "1386623436"
  | ["datetaken"]=>
  | string(19) "2013-12-08 21:35:02"
  | ["datetakengranularity"]=>
  | string(1) "0"
  | ["datetakenunknown"]=>
  | int(0)
  | ["originalsecret"]=>
  | string(10) "8ff277ba30"
  | ["originalformat"]=>
  | string(3) "jpg"
  | }
MartinKlefas commented 6 years ago

OK - sorry for the repeated posts - I now don't know if this is a change in this fork or a change implemented some time ago that has only come to light since my upgrade. It seems that the returned photoset array used to contain an element ['photo'] at it's root - but this is now found at ['photoset']['photo']. Changing references to this allows the set page to work properly.