Ethan
Ethan

Reputation: 3818

How to get a list of all a specific user's photos using Unsplash API?

It it possible to get a list of all the photos or photo IDs by a specific user on Unsplash using the Unsplash API?

Upvotes: 1

Views: 2071

Answers (2)

Jose Ortega
Jose Ortega

Reputation: 1040

Actually per_page is limited to 30. This would be my answer on here (I've been working with this on PowerShell) I've created a script to get a bearer token that can be read in here: https://github.com/j0rt3g4/MyTechNetScript/blob/master/TechNet/Unsplash/Do-Oauth20forUnsplash.md#Create-an-account-on-unsplash

and here: https://medium.com/@josegabrielortegac/how-to-fix-capture-one-software-c3e59b2924da

and downloaded here: https://gallery.technet.microsoft.com/scriptcenter/Get-Bearer-Token-to-use-360f9ae2

or here (because TechNet would be closing soon) https://github.com/j0rt3g4/MyTechNetScript/blob/master/TechNet/Unsplash/Do-Oauth20forUnsplash.ps1

my solution for this is after getting the Bearer token from the script, you can use it on any app because that particular token never expires. you'd need just to add the "Authorization", "Bearer Token" header, where token should be changed by the value received by the script and after that, you can just get the count:

Total Number of pictures / 30 (images per page)

In my case my account has right now 750 pictures so that number gives = 25. and run this:

$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization","Bearer <beater token value>")

for($i=1; $i -lt 25;$i++){
    $obj+= Invoke-WebRequest -Uri "https://api.unsplash.com/users/j0rt/photos?per_page=30&page=$i&order_by=latest&stats=true" -Headers $headers | select -ExpandProperty Content | ConvertFrom-Json # | select Downloads,Views,Likes
}

Upvotes: 2

Yoryo
Yoryo

Reputation: 270

According to their API documentation it should be possible:

https://unsplash.com/documentation#list-a-users-photos

You can do that by sending an XHR GET request to their API url:

GET /users/:username/photos

In addition, you can use the parameters page and per_page to increase/decrease the number of photos returned in the request, and therefore, get all the photos of that specific user within one request. I do not see in their documentation an established hard limit on the number of items per_page, which by default is 10.

Upvotes: 2

Related Questions