Open blaugold opened 3 years ago
Currently working on registering the download since the current method doesn't work
@edgarjc Could you share a bit more about what does not work? Do you get an error?
The download method isn't actually "downloading" the image from unsplash. It seems like the get request isn't being sent correctly. After some digging, it looks like it takes in an id which according to their API isn't necessarily correct since each image has its own unique download token under download_location. I passed that dowload_location into the function It's still not tracking downloads.
Hm. The Photos.download
method should simply implement the GET /photos/:id/download endpoint, and I don't see what could be wrong in the implementation. photo.links.download_location
just seems to be a prebuilt URL to this endpoint for a particular photo.
If you are not immediately seeing the download counter of a photo increment, it could be that unsplash does some caching, and it takes a bit of time to reflect the download.
So after a lot of troubleshooting, I think that the Request isn't correctly sending the Unsplash client credentials but I might be wrong about that. In the meantime the code below is what correctly implements the GET request in my project and it shows the download on the Unsplash dashboard.
final response = await http.get(
Uri.parse("${downloadLink}&client_id=${unsplashAccessKey}"),
);
return response;
Thanks for the update! I've looked at the official unsplash client for JS and there the client id is sent in the Authorization
header just like this client does. There is no special handling of the URL for the download endpoint where the client_id
is added to it. My guess is that the server does not implement the endpoint quite right and only uses the client id when sent in the URL. But I think the Photos.download
should require that the user passes in the download_location
URL, since that is how the JS client does, probably to make sure the other parameters in download_location
are provided.
This method should download the image of the photo as well as hit the Unsplash API endpoint to register the download.