You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Now that you have an authentication url, you'll want to redirect the user to it.
location.assign(authenticationUrl);
After the user authorizes your app she'll be redirected to your callback url with a code querystring present. Request an access token using that code.
// The OAuth code will be passed to your callback url as a querystringunsplash.auth.userAuthentication(query.code).then(toJson).then(json=>{unsplash.auth.setBearerToken(json.access_token);});
Note: this accepts a photo JSON object, not a URL string or photo ID. See the example below for how to pair it with other calls to trigger it.
Arguments
Argument
Type
Opt/Required
photo
json
Required
Example
unsplash.photos.getPhoto("mtNweauBsMQ").then(toJson).then(json=>{unsplash.photos.downloadPhoto(json);});// or if working with an array of photosunsplash.search.photos("dogs",1).then(toJson).then(json=>{unsplash.photos.downloadPhoto(json["results"][0]);});
Remove a photo from one of the logged-in user’s collections. Requires the write_collections scope.
Arguments
Argument
Type
Opt/Required
collectionId
number
Required
photoId
string
Required
Example
unsplash.collections.removePhotoFromCollection(88,'abc1234').then(toJson).then(json=>{// Your code});
collections.listRelatedCollections(collectionId)
Lists collections related to the provided one.
Arguments
Argument
Type
Opt/Required
collectionId
number
Required
Example
unsplash.collections.listRelatedCollections(88).then(toJson).then(json=>{// Your code});
search.photos(keyword, page, per_page)
Get a list of photos matching the keyword.
Arguments
Argument
Type
Opt/Required
Default
keyword
string
Required
page
number
Optional
per_page
number
Optional
10
Example
unsplash.search.photos("dogs",1).then(toJson).then(json=>{// Your code});
search.users(keyword, page, per_page)
Get a list of users matching the keyword.
Arguments
Argument
Type
Opt/Required
Default
keyword
string
Required
page
number
Optional
per_page
number
Optional
10
Example
unsplash.search.users("steve",1).then(toJson).then(json=>{// Your code});
search.collections(keyword, page, per_page)
Get a list of collections matching the keyword.
Arguments
Argument
Type
Opt/Required
Default
keyword
string
Required
page
number
Optional
per_page
number
Optional
10
Example
unsplash.search.collections("dogs",1).then(toJson).then(json=>{// Your code});
stats.total()
Get a list of download counts for all of Unsplash.
Arguments
N/A
Example
unsplash.stats.total().then(toJson).then(json=>{// Your code});
Helpers
toJson(res)
Arguments
Argument
Type
Opt/Required
res
Object
Required
Example
importUnsplash,{toJson}from"unsplash-js";constunsplash=newUnsplash({applicationId: "{YOUR_ACCESS_KEY}",secret: "{YOUR_SECRET_KEY}"});unsplash.stats.total().then(toJson).then(json=>{// Your code});
Shoutouts
Shoutout to all the contributors for lending a helping hand.
Shoutout to BrowserStack for letting us use their service to run automated browser tests.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.