Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Photos.downloadImage method to download image of photo #11

Open
blaugold opened this issue Apr 19, 2021 · 6 comments
Open

Add Photos.downloadImage method to download image of photo #11

blaugold opened this issue Apr 19, 2021 · 6 comments
Labels
enhancement New feature or request

Comments

@blaugold
Copy link
Owner

This method should download the image of the photo as well as hit the Unsplash API endpoint to register the download.

@blaugold blaugold added the enhancement New feature or request label Apr 19, 2021
@edgarjc
Copy link

edgarjc commented Nov 15, 2022

Currently working on registering the download since the current method doesn't work

@blaugold
Copy link
Owner Author

blaugold commented Nov 15, 2022

@edgarjc Could you share a bit more about what does not work? Do you get an error?

@edgarjc
Copy link

edgarjc commented Nov 15, 2022

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.

@blaugold
Copy link
Owner Author

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.

@edgarjc
Copy link

edgarjc commented Nov 16, 2022

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;

@blaugold
Copy link
Owner Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants