dblock / strava-ruby-client

A complete Ruby client for the Strava API v3.
https://code.dblock.org/2018/11/27/writing-a-new-strava-api-ruby-client.html
MIT License
97 stars 22 forks source link

Problem getting photo URLs via `client.activity_photos` #76

Closed josh-works closed 1 year ago

josh-works commented 1 year ago

Here's my rails console commands:

photos = client.activity_photos(activity.id)
# returns a bunch of photos

photo = photos.first
=> #<Strava::Api::Pagination:0x0000000107cc1f48
 @collection=
  [{"unique_id"=>"1e5bacd2-9fee-409f-8dd9-be7c33a653ce",
    "athlete_id"=>38072598,
    "activity_id"=>9216986893,
    "activity_name"=>"Great day ",
    "resource_state"=>2,
    "caption"=>"",
    "source"=>1,
    "uploaded_at"=>2023-06-06 23:52:49 UTC,
    "created_at"=>2023-06-06 19:04:17 UTC,
    "created_at_local"=>2023-06-06 13:04:17 UTC,
    "urls"=>{"1800"=>"https://d3nn82uaxijpm6.cloudfront.net/assets/media/placeholder-photo@4x-13b0b44cfa828acc8b95d8dc4b8157d87666aa1ea8ef814c6ec36cd542d2b756.png"},
    "sizes"=>{"1800"=>[1372, 1000]},
    "default_photo"=>false},

That URL is a placeholder image - how do I get the real image URL?

You can click https://d3nn82uaxijpm6.cloudfront.net/assets/media/placeholder-photo@4x-13b0b44cfa828acc8b95d8dc4b8157d87666aa1ea8ef814c6ec36cd542d2b756.png - it's a very boring grey arrow. What I actually want is https://dgtzuqphqg23d.cloudfront.net/d-SgDjqAYTTEb2_uXnhC0UoND2CErBxV38KFl_uPO0g-1536x2048.jpg, a very pretty traffic cone.

How do I get from one to the other?

simonneutert commented 1 year ago

Hey @josh-works,

yes, this looks like a bug.

You should be able to query an activity's photos by using:

activity = client.activity(activity.id)
photos = activity.photos

return value looks sth like this:

{"primary"=>
  {"unique_id"=>"f5ebd6e7-86ce-ce5cf31cf519",
   "urls"=>
    {"600"=>"https://dgtzuqphqg23d.cloudfront.net/3wt2DHX6gJSXzpAcVdEI1Q0CX2w4-768x576.jpg",
     "100"=>"https://dgtzuqphqg23d.cloudfront.net/3wt2DHX6gJSXzpAcVdEI1Q0CX2w4-128x96.jpg"},
   "source"=>1},
 "use_primary_photo"=>false,
 "count"=>2}

The limitation in size is hopefully sth you can live with in the meantime 🤞

simonneutert commented 1 year ago

To me it looks like they crippled the endpoint to retrieve photos: activities/#{id}/photos.

In the official docs of Strava v3, there is no sign of the endpoint being supported. When you search the docs for photos, you won't find a route pointing to activities/#{id}/photos sadly.

simonneutert commented 1 year ago

I provided two PR for v1.x and the upcoming v2 release of this gem.

Other implementations of clients seem to drop support / deprecate photos, too.
See https://github.com/node-strava/node-strava-v3#activities

josh-works commented 1 year ago

yes, this looks like a bug.

You should be able to query an activity's photos by using:

activity = client.activity(activity.id)
photos = activity.photos

return value looks sth like this:

{"primary"=>
  {"unique_id"=>"f5ebd6e7-86ce-ce5cf31cf519",
   "urls"=>
    {"600"=>"https://dgtzuqphqg23d.cloudfront.net/3wt2DHX6gJSXzpAcVdEI1Q0CX2w4-768x576.jpg",
     "100"=>"https://dgtzuqphqg23d.cloudfront.net/3wt2DHX6gJSXzpAcVdEI1Q0CX2w4-128x96.jpg"},
   "source"=>1},
 "use_primary_photo"=>false,
 "count"=>2}

The limitation in size is hopefully sth you can live with in the meantime 🤞

This is perfect, @simonneutert, thank you. I'd not tried this method of getting to photos, embarrassed to say I didn't see it in the Strava docs.

I'm having trouble accessing additional photos for an activity - I can find a single photo, but when I call activity.photos, I get back a single object that hints at more like it, somewhere:

activity.photos
=>
{"primary"=>
  {"unique_id"=>"1e5bacd2-9fee-409f-8dd9-be7c33a653ce",
   "urls"=>
    {"600"=>"https://dgtzuqphqg23d.cloudfront.net/FVmA1bREMifCa_SEqMK6pqczk-4lQDC87F8Ep-qAegM-768x576.jpg",
     "100"=>"https://dgtzuqphqg23d.cloudfront.net/FVmA1bREMifCa_SEqMK6pqczk-4lQDC87F8Ep-qAegM-128x96.jpg"},
   "source"=>1},
 "use_primary_photo"=>true,
 "count"=>18}

I would expect activity.photos to be an array of multiple photo objects, instead of a single object. Obviously something funny is up with the Strava API. I am surprised to see that there might not be a way to get all photos.

I can certainly make do with this limitation in size. Photos at all, even one is infinitely better than no photos!