blaugold / unsplash_client

An unofficial, platform independent, client for the Unsplash API. Unsplash provides royalty-free images.
https://pub.dev/packages/unsplash_client
BSD 3-Clause "New" or "Revised" License
24 stars 7 forks source link

Track download wrong url #21

Closed stact closed 9 months ago

stact commented 9 months ago

Related to the guidelines about tracking downloads it must call a specific endpoint.

https://help.unsplash.com/en/articles/2511245-unsplash-api-guidelines

What we have: Screenshot 2023-12-27 at 20 42 28

Related to the guideline:

{
  "id": "LBI7cgq3pbM",
  "width": 5245,
  "height": 3497,
  "color": "#60544D",
  "urls": { ... },
  "user": { ... },
  "links": {
    "self": "https://api.unsplash.com/photos/LBI7cgq3pbM",
    "html": "https://unsplash.com/photos/LBI7cgq3pbM",
    "download": "https://unsplash.com/photos/LBI7cgq3pbM/download", // don't use this property
    "download_location": "https://api.unsplash.com/photos/LBI7cgq3pbM/download?ixid=MnwxMTc4ODl8MHwxfHNlYXJjaHwxfHxwdXBweXxlbnwwfHx8fDE2MTc3NTA2MTM" // use this one ;)
  }
}

Maybe instead of String id, we need to have String download_location

Temporary fix:

Request<TrackPhotoDownload> download(String downloadLocation) {
  final url = Uri.parse(downloadLocation);

  return Request(
    client: _client,
    httpRequest: http.Request('GET', url),
    isPublicAction: true,
    bodyDeserializer: (dynamic json) => TrackPhotoDownload.fromJson(json as Map<String, dynamic>),
  );
}
blaugold commented 9 months ago

Thanks for reporting this!

blaugold commented 9 months ago

Version 2.2.0 with support for passing location to Photos.download has been released.