bluefantail / flickrGal

flickrGal is a fully responsive gallery utilising the flickr api. Written in pure javascript, with no external dependencies.
14 stars 1 forks source link

Cover images don't display for newly created albums, until the cover image has been set again manually on flickr #28

Closed bluefantail closed 7 years ago

bluefantail commented 8 years ago

Not really sure why. Perhaps the cover image url doesn't get set until the user changes it? ... Seems odd

bluefantail commented 8 years ago

Hard to test because have to make a new album each time

bluefantail commented 8 years ago

Could use the first image in each album instead of the one passed through with 'flickr.collections.getTree' instead, but that will add an extra call, so rather not do that. I'm sure this wasn't a problem in the past.

bluefantail commented 7 years ago

Definitely appears to be some kind of bug in the flickr api here.

There seems to be a discrepancy between what flickr.photosets.getPhotos and flickr.photosets.getList returns in the way of primary photo information.

On a brand new test photoset, without specifically setting a cover image in flickrs organiser (which involves setting the cover image to something else, saving the album, and then back to the correct image, saving again), a flickr.photosets.getPhotos returns a photoset without any photo with "isprimary": 1 set.

Example:

https://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&api_key=b6066aaebcfa55602f236f3ab78064ad&photoset_id=72157667495622524&user_id=141088533%40N02&format=json&nojsoncallback=1

Returns the image that is supposed to be primary with "isprimary": 0, instead of "isprimary": 1

{ "photoset": { "id": "72157667495622524", "primary": "27296003713", "owner": "141088533@N02", "ownername": "flikrgaldemo", 
    "photo": [
      { "id": "27296003713", "secret": "da17dc8f8e", "server": "7297", "farm": 8, "title": "blur - Copy", "isprimary": 0, "ispublic": 1, "isfriend": 0, "isfamily": 0 }
    ], "page": 1, "per_page": "500", "perpage": "500", "pages": 1, "total": 1, "title": "Test Album" }, "stat": "ok" }

However, a flickr.photosets.getList with the url_m primary_photo_extras returns a list of photosets with all the correct primary photo urls, including the new test album. This means the primary image is actually set somewhere, and I would presume that "isprimary": 1 should therefore logically be returned on an image when using flickr.photosets.getPhotos.

Example of this Behavior:

https://api.flickr.com/services/rest/?method=flickr.photosets.getList&api_key=b6066aaebcfa55602f236f3ab78064ad&user_id=141088533%40N02&primary_photo_extras=url_m&format=json&nojsoncallback=1

Returns the working test album image's primary photo url just fine:

{ "photosets": { "page": 1, "pages": 1, "perpage": 7, "total": 7, 
    "photoset": [
      { "id": "72157667495622524", "primary": "27296003713", "secret": "da17dc8f8e", "server": "7297", "farm": 8, "photos": 1, "videos": 0, 
        "title": { "_content": "Test Album" }, 
        "description": { "_content": "" }, "needs_interstitial": 0, "visibility_can_see_set": 1, "count_views": 0, "count_comments": 0, "can_comment": 0, "date_create": "1466907849", "date_update": "1466907850", 
        "primary_photo_extras": { "url_m": "https:\/\/farm8.staticflickr.com\/7297\/27296003713_da17dc8f8e.jpg", "height_m": "196", "width_m": "500" } },
      { "id": "72157665357058390", "primary": "25797356455", "secret": "2cc406ebfc", "server": "1612", "farm": 2, "photos": 11, "videos": 0, 
        "title": { "_content": "Into the Woods" }, 
        "description": { "_content": "" }, "needs_interstitial": 0, "visibility_can_see_set": 1, "count_views": 6, "count_comments": 0, "can_comment": 0, "date_create": "1458002995", "date_update": "1458002997", 
        "primary_photo_extras": { "url_m": "https:\/\/farm2.staticflickr.com\/1612\/25797356455_2cc406ebfc.jpg", "height_m": "333", "width_m": "500" } },
      { "id": "72157665885687766", "primary": "25797863415", "secret": "9038c8257c", "server": "1624", "farm": 2, "photos": 6, "videos": 0, 
        "title": { "_content": "Portrait" }, 
        "description": { "_content": "" }, "needs_interstitial": 0, "visibility_can_see_set": 1, "count_views": 0, "count_comments": 0, "can_comment": 0, "date_create": "1458001862", "date_update": "1458002851", 
        "primary_photo_extras": { "url_m": "https:\/\/farm2.staticflickr.com\/1624\/25797863415_9038c8257c.jpg", "height_m": "500", "width_m": "386" } },
      { "id": "72157663616025873", "primary": "25797697295", "secret": "a8b1a59649", "server": "1614", "farm": 2, "photos": 14, "videos": 0, 
        "title": { "_content": "Wet" }, 
        "description": { "_content": "" }, "needs_interstitial": 0, "visibility_can_see_set": 1, "count_views": 0, "count_comments": 0, "can_comment": 0, "date_create": "1458001488", "date_update": "1458002899", 
        "primary_photo_extras": { "url_m": "https:\/\/farm2.staticflickr.com\/1614\/25797697295_a8b1a59649.jpg", "height_m": "281", "width_m": "500" } },
      { "id": "72157663615188973", "primary": "25702059311", "secret": "05f61de4da", "server": "1624", "farm": 2, "photos": 12, "videos": 0, 
        "title": { "_content": "Instant" }, 
        "description": { "_content": "" }, "needs_interstitial": 0, "visibility_can_see_set": 1, "count_views": 0, "count_comments": 0, "can_comment": 0, "date_create": "1457999573", "date_update": "1458005155", 
        "primary_photo_extras": { "url_m": "https:\/\/farm2.staticflickr.com\/1624\/25702059311_05f61de4da.jpg", "height_m": "333", "width_m": "500" } },
      { "id": "72157663614791743", "primary": "25170320503", "secret": "47f3464516", "server": "1649", "farm": 2, "photos": 9, "videos": 0, 
        "title": { "_content": "Cloudy" }, 
        "description": { "_content": "" }, "needs_interstitial": 0, "visibility_can_see_set": 1, "count_views": 0, "count_comments": 0, "can_comment": 0, "date_create": "1457998697", "date_update": "1458003070", 
        "primary_photo_extras": { "url_m": "https:\/\/farm2.staticflickr.com\/1649\/25170320503_47f3464516.jpg", "height_m": "357", "width_m": "500" } },
      { "id": "72157665783513431", "primary": "25495911900", "secret": "7291da9839", "server": "1655", "farm": 2, "photos": 8, "videos": 0, 
        "title": { "_content": "Explore Canada" }, 
        "description": { "_content": "" }, "needs_interstitial": 0, "visibility_can_see_set": 1, "count_views": 2, "count_comments": 0, "can_comment": 0, "date_create": "1457997985", "date_update": "1458005127", 
        "primary_photo_extras": { "url_m": "https:\/\/farm2.staticflickr.com\/1655\/25495911900_7291da9839.jpg", "height_m": "334", "width_m": "500" } }
    ] }, "stat": "ok" }

To me this discrepancy seems contradictory, surely it can't be by design?

There are tradeoffs for using any other method here, which will inevitably add extra calls before I can begin constructing photoset image urls.

bluefantail commented 7 years ago

Closing with the best compromise I could find, should work in 99% of cases.

Just adding fallback to simply use the first image in the returned photoset, when a specific primary photo is not set.