
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
unsplash-js
Advanced tools
A Universal JavaScript wrapper for the Unsplash API.
Before using the Unsplash API, you need to register as a developer and read the API Guidelines.
![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
---|---|---|---|---|---|
Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | 10+ ✔ |
Quick links to methods you're likely to care about:
Note: Every application must abide by the API Guidelines. Specifically, remember to hotlink images and trigger a download when appropriate.
$ npm i --save unsplash-js
This library depends on fetch to make requests to the Unsplash API. For environments that don't support fetch, you'll need to provide a polyfill.
To create an instance, simply provide an Object with your applicationId
, secret
and callbackUrl
.
import Unsplash from 'unsplash-js';
const unsplash = new Unsplash({
applicationId: "{APP_ID}",
secret: "{APP_SECRET}",
callbackUrl: "{CALLBACK_URL}"
});
If you already have a bearer token, you can also provide it to the constructor.
const unsplash = new Unsplash({
applicationId: "{APP_ID}",
secret: "{APP_SECRET}",
callbackUrl: "{CALLBACK_URL}",
bearerToken: "{USER_BEARER_TOKEN}"
});
You can also provide headers that will be set on every request by providing them to the constructor.
const unsplash = new Unsplash({
applicationId: "{APP_ID}",
secret: "{APP_SECRET}",
callbackUrl: "{CALLBACK_URL}",
headers: {
"X-Custom-Header": "foo"
}
});
Credentials can be obtained from Unsplash Developers.
For use with React Native, import from unsplash-js/native
instead.
import Unsplash from 'unsplash-js/native';
Generate an authentication url with the scopes your app requires.
const authenticationUrl = unsplash.auth.getAuthenticationUrl([
"public",
"read_user",
"write_user",
"read_photos",
"write_photos"
]);
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 querystring
unsplash.auth.userAuthentication(query.code)
.then(toJson)
.then(json => {
unsplash.auth.setBearerToken(json.access_token);
});
For more information on the authroization workflow, consult the Unsplash Documentation.
unsplash.users.profile("naoufal")
.catch(err => {
// Your flawless error handling code
});
All the instance methods below make use of the toJson
helper method described below
FAQs
Official JavaScript wrapper for the Unsplash API
The npm package unsplash-js receives a total of 41,778 weekly downloads. As such, unsplash-js popularity was classified as popular.
We found that unsplash-js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.