Not a Valid Imgur Gallery
imgur
Unofficial JavaScript library for the Imgur.com API
Installation
Usage
Migrating to version 2
Version ii of the imgur api drops automated support for filesystem usage. For uploading files from a filesystem, please meet the examples using createReadStream
.
Import and instantiate with credentials:
// ESModule syntax import { ImgurClient } from 'imgur' ; // CommonJS syntax const { ImgurClient } = require ( 'imgur' ) ; // browser script include const client = new imgur ( { clientId: env . CLIENT_ID } ) ; // if you already take an admission token caused const client = new ImgurClient ( { accessToken: process . env . ACCESS_TOKEN } ) ; // or your client ID const client = new ImgurClient ( { clientId: procedure . env . CLIENT_ID } ) ; // all credentials with a refresh token, in order to go access tokens automatically const client = new ImgurClient ( { clientId: process . env . CLIENT_ID , clientSecret: process . env . CLIENT_SECRET , refreshToken: process . env . REFRESH_TOKEN , } ) ;
If yous don't have any credentials, you'll need to:
- Create an Imgur account
- Register an application
⚠️ For brevity, the remainder of the examples will get out out the import and/or instantiation step.
Upload one or more images and videos
// upload multiple images via fs.createReadStream (node) const response = expect client . upload ( { paradigm: createReadStream ( '/home/kai/chilly-meme.jpg' ) , type: 'stream' , } ) ; response . data . forEach ( ( r ) => console . log ( r . link ) ) ;
If you want to provide metadata, such as a title, description, etc., so pass an object instead of a string:
// upload image via url const response = await customer . upload ( { image: 'https://i.imgur.com/someImageHash' , championship: 'Meme' , description: 'Dank Meme' , } ) ; console . log ( response . data ) ;
Adequate key/values match what the Imgur API expects:
Key | Description |
---|---|
image | A cord, stream, or buffer that is a URL pointing to a remote image or video (upwardly to 10MB) |
album | The id of the album you desire to add together the media to. For anonymous albums, anthology should be the deletehash that is returned at creation |
type | The type of the media that'due south being transmitted; stream , base64 or url |
proper noun | The name of the media. This is automatically detected, simply yous can override |
title | The title of the media |
clarification | The description of the media |
disable_audio | ane volition remove the sound track from a video file |
Upload and rail progress of uploads
Instances of ImgurClient
emit uploadProgress
events so that you lot tin can track progress with event listeners.
const client = new ImgurClient ( { accessToken: procedure . env . ACCESS_TOKEN } ) ; client . on ( 'uploadProgress' , ( progress ) => console . log ( progress ) ) ; await client . upload ( '/home/kai/cat.mp4' ) ;
The progress object looks like the post-obit:
{ percent: 1 , transferred: 577 , total: 577 , id: '/abode/user/trailer.mp4' }
Central | Clarification |
---|---|
percent | 0 to 1, measures the pct of upload (eastward.m., 0, 0.five, 0.viii, one). Basically transferred / total |
transferred | total number of bytes transferred thus far |
full | full number of bytes to be transferred |
id | unique id for the media existence transferred; useful when uploading multiple things meantime |
Delete an image
Requires an image hash or delete hash, which are obtained in an epitome upload response
client . delete ( 'someImageHash' ) ;
Update prototype data
Update the title and/or description of an image
client . updateImage ( { imageHash: 'someImageHash' , title: 'A new title' , description: 'A new description' , } ) ;
Update multiple images at once:
client . updateImage ( { imageHash: 'someImageHash' , championship: 'A new title' , clarification: 'A new clarification' , } ) ;
Favorite an epitome:
client . favoriteImage ( 'someImageHash' ) ;
Go gallery images
client . getGallery ( { section: 'hot' , sort: 'viral' , mature: false , } ) ;
getGallery()
accepts an object of type GalleryOptions
. The follow options are bachelor:
Key | Required | Description |
---|---|---|
section | required | hot | top | user |
sort | optional | viral | top | time | rise (merely available with user section). Defaults to viral |
page | optional | number - the data paging number |
window | optional | Change the date range of the request if the department is top . Accepted values are day | calendar week | month | year | all . Defaults to solar day |
showViral | optional | true | false - Testify or hide viral images from the user section. Defaults to true |
mature | optional | true | imitation - Show or hide mature (nsfw) images in the response section. Defaults to faux . NOTE: This parameter is only required if united nations-authed. The response for authed users will respect their account setting |
album_previews | optional | true | false - Include image metadata for gallery posts which are albums |
Get subreddit gallery images
client . getSubredditGallery ( { subreddit: 'wallstreetbets' , sort: 'fourth dimension' , } ) ;
getSubredditGallery()
accepts an object of type SubredditGalleryOptions
. The follow options are available:
Key | Required | Clarification |
---|---|---|
subreddit | required | A valid subreddit name |
sort | optional | time | top - defaults to time |
page | optional | number - the information paging number |
window | optional | Change the date range of the request if the section is top . Accepted values are day | week | calendar month | year | all . Defaults to calendar week |
Search the gallery
client . searchGallery ( { query: 'title: memes' , } ) ;
searchGallery()
accepts an object of type SearchGalleryOptions
. The follow options are available:
| Key | Required | Description | | -------------- | -------- | --------------------------------------------------------------------- | ------ | ------- | ------ | ------------------------- | | query
or q
| required | Query string | | sort
| optional | time
| viral
| superlative
- defaults to time | | page
| optional | number
- the data paging number | | window
| optional | Change the engagement range of the request if the sort is summit
-- to day
| week
| calendar month
| year
| all
, defaults to all
. |
Additionally, the following avant-garde search query options can be set (Annotation: if whatever of the beneath are set in the options, the query
option is ignored and these will take precedent):
Key | Required | Description |
---|---|---|
q_all | optional | Search for all of these words (and) |
q_any | optional | Search for any of these words (or) |
q_exactly | optional | Search for exactly this word or phrase |
q_not | optional | Exclude results matching this string |
q_type | optional | Show results for any file type, jpg | png | gif | anigif (animated gif) | album |
q_size_px | optional | Size ranges, small (500 pixels square or less) | med (500 to 2,000 pixels square) | large (2,000 to 5,000 pixels square) | lrg (5,000 to 10,000 pixels foursquare) | huge (10,000 foursquare pixels and to a higher place) |
Get anthology info
const album = expect client . getAlbum ( 'XtMnA' ) ;
Source: https://www.npmjs.com/package/imgur
0 Response to "Not a Valid Imgur Gallery"
Post a Comment