Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
unsplash-js
Advanced tools
A Universal JavaScript wrapper for the Unsplash API.
Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | 10+ ✔ |
$ npm i --save unsplash-js
This library depends on fetch to make requests to the Unsplash API. For browsers 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
.
let 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.
let unsplash = new Unsplash({
applicationId: "{APP_ID}",
secret: "{APP_SECRET}",
callbackUrl: "{CALLBACK_URL}",
bearerToken: "{USER_BEARER_TOKEN}"
});
Credentials can be obtained from Unsplash Developers.
Generate an authentication url with the scopes your app requires.
let 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
});
FAQs
Official JavaScript wrapper for the Unsplash API
The npm package unsplash-js receives a total of 52,113 weekly downloads. As such, unsplash-js popularity was classified as popular.
We found that unsplash-js demonstrated a healthy version release cadence and project activity because the last version was released less than 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
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.