如何使用Unsplash API获取所有特定用户照片的列表?

时间:2018-02-23 00:01:52

标签: api

使用Unsplash API可以在Unsplash上​​获取特定用户的所有照片或照片ID列表吗?

2 个答案:

答案 0 :(得分:2)

实际上,每页限制为30。 这就是我在这里的答案(我一直在PowerShell上使用它) 我创建了一个脚本来获取可在此处读取的承载令牌: https://github.com/j0rt3g4/MyTechNetScript/blob/master/TechNet/Unsplash/Do-Oauth20forUnsplash.md#Create-an-account-on-unsplash

在这里: https://medium.com/@josegabrielortegac/how-to-fix-capture-one-software-c3e59b2924da

,并在此处下载: https://gallery.technet.microsoft.com/scriptcenter/Get-Bearer-Token-to-use-360f9ae2

或此处(因为TechNet即将关闭) https://github.com/j0rt3g4/MyTechNetScript/blob/master/TechNet/Unsplash/Do-Oauth20forUnsplash.ps1

我的解决方案是从脚本中获取Bearer令牌后,您可以在任何应用程序上使用它,因为该特定令牌永不过期。您只需要添加“ Authorization”,“ Bearer Token”标头,应通过脚本接收的值更改令牌,然后,您可以获取计数:

Total Number of pictures / 30 (images per page)

在我的情况下,我的帐户现在有750张照片,因此该数字为25。 并运行:

$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
}

答案 1 :(得分:1)

根据他们的API文档,应该可以:

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

您可以通过向其API网址发送XHR GET请求来执行此操作:

GET /users/:username/photos

此外,您可以使用参数pageper_page来增加/减少请求中返回的照片数量,从而在一个请求中获取该特定用户的所有照片。我在他们的文档中没有看到项目数量per_page的既定硬限制,默认情况下为10。