Body Worlds All Pictures Imgur
You are here: Home / API Tutorial / API Tutorial: Using Imgur API to search for images
Imgur is an online image hosting and sharing community website, founded by Alan Schaaf in 2009 and created specifically to host images for the online community Reddit.
It's a popular service, described by some as one of the best image APIs compared to its major competitors. It receives monthly more than 474 Million estimated visits according to Similarweb:
In this tutorial, we will cover how to leverage the Imgur database to retrieve galleries and their images, in addition to the comments left for a particular image via their restful API using javascript and node.js.
Table of Contents
- 1 Setup
- 1.1 Getting the Javascript Code
- 1.2 Start with Signing Up to Rakuten RapidApi
- 2 Authentication
- 3 Imgur API Overview
- 4 Making sense of the Imgur image database
- 4.1 Searching galleries
- 4.2 Get gallery image comment Ids
- 4.3 Get image comment replies
- 5 That's It
- 6 About Rakuten RapidAPI
- 6.1 Share this:
Setup
To get started you'll need
- Javascript editor and npm unirest package that will speed up code writing
- Rakuten RapidApi account and the API key that comes with it
Getting the Javascript Code
Rakuten RapidApi got you covered and packaged all the javascript code you need to work with the API in an easy unirest SDK, which is a library to simplify HTTP REST requests and save you time writing code.
Get started by installing the unirest package with the following command:
npm install unirest --save
As soon as that's done, you can start exploring the API. It's safe to ignore the npm warn messages at this point if you see any.
Start with Signing Up to Rakuten RapidApi
About Rakuten RapidAPI
Rakuten RapidAPI is the world's largest API marketplace with 8,000+ third-party APIs and used by over 500,000 active developers. We enable developers to build transformative apps through the power of APIs. Find, test and connect to all the APIs you need in one place!
We've also got you covered with Imgur API access. You can try it without leaving the browser, on the Imgur API page. You'll need to sign up to get the API keys and make requests to the API. With these keys you'll be able to make and authenticate the requests, so we will know they come from you.
As soon as you sign-in with your account, the view above will be replaced with another view, where you can see your API keys (X-RapidAPI-Key) in the Request Headers section and a ready to copy snippet of code at the right side.
Authentication
In order to use the Imgur restful API, you first have to sign up for an Imgur account following these steps. Once that's done, you'll get a client_id that you can send in the Authorization header to authenticate your requests.
Imgur API Overview
Imgur provides through Rakuten RapidAPI multiple API categories, however in this tutorial we'll focus on the following endpoints:
- Get Gallery: Endpoint that search the available galleries in imgur and returns metadata about each one of them.
- Get Gallery Image Comment Ids: Endpoint that lists all of the comment ids in an array for a gallery item
- Get Comment Replies: Endpoint that return the comment and the thread of replies
Making sense of the Imgur image database
In this tutorial, we're going to use the Imgur API to retrieve the galleries and images uploaded to Imgur and the comments tree for a specific image.
Let's get started.
Searching galleries
The first endpoint we will be covering allows searching for the galleries in Imgur.
These are the parameters we need to set; a sort parameter that allows us to specify whether we would like to sort by time added or virality of the gallery. The section parameter allows specifying which section we would like to search:
Query Params:
sort | string | Viral | time – defaults to viral |
section | string | hot | top | user – defaults to hot |
Upon successful completion, the API returns the following response body:
Response body:
{ "data": { "id": "qJj7aZ0", // Id of the gallery "title": "The real Battle Royale", // Title of the gallery "description": null, "datetime": 1551005187, // Date posted "cover": "CzoosPe", "cover_width": 1106, "cover_height": 1225, "account_url": "Typep91", // Username of the uploader "account_id": 21745067, "privacy": "public", "layout": "blog", "views": 66731, "link": "https://imgur.com/a/qJj7aZ0", // Link to the gallery "ups": 1774, // upvotes "downs": 50, // Downvotes "points": 1724, "score": 1757, "is_album": true, "vote": null, "favorite": false, "nsfw": false, "section": "", "comment_count": 247, // Number of comments for the gallery "favorite_count": 284, // Number of times marked as favourite "topic": "No Topic", // Topic to which the gallery is assigned "topic_id": 29, "images_count": 1, // Number of images in the gallery "in_gallery": true, "is_ad": false, "tags": [], "ad_type": 0, "ad_url": "", "in_most_viral": true, "include_album_ads": false, "images": [ {} ], "ad_config": { "safeFlags": [ "onsfw_mod_safe", "share" ], "highRiskFlags": [ "not_in_gallery" ], "unsafeFlags": [], "showsAds": true } }, "success": true, "status": 200 }
Code snippet:
const unirest = require('unirest'); const API_KEY = "YOUR_API_KEY_HERE"; const CLIENT_ID = "YOUR_CLIENT_ID"; unirest.get("https://imgur-apiv3.p.rapidapi.com/3/gallery/hot/viral/{window}/{page}") .header("X-RapidAPI-Key", API_KEY) .header("Authorization", `Client-ID ${CLIENT_ID}`) .end(function (result) { console.log(JSON.stringify(result.body, null, 4)); });
This endpoint allows retrieving the ids of the top level comments for a particular image, identified by its unique Id.
Query Params:
id | string | Id of the image for which we would like the comments ids to be retrieved |
Upon successful completion the API returns the following response body, which contains a success and status properties that provide information on the status of the request, in addition to a data property containing the top level comment Ids:
Response body:
{ "data": [ 1591379041, 1591402037, 1591399349, 1591439825, 1591432417, 1591398693, 1591397829, 1591390589, 1591382649, 1591472981, 1591471981, 1591471905, 1591468081 ], "success": true, "status": 200 }
Code snippet:
const unirest = require('unirest'); const API_KEY = "YOUR_API_KEY"; const CLIENT_ID = "YOUR_CLIENT_ID"; unirest.get("https://imgur-apiv3.p.rapidapi.com/3/gallery/AJ6sEjQ/comments/ids") .header("X-RapidAPI-Key", API_KEY) .header("Authorization", `Client-ID ${CLIENT_ID}`) .end(function (result) { console.log(JSON.stringify(result.body, null, 4)); });
This endpoint allows retrieving the comment replies for a parent comment:
Query Params:
id | string | The id for the comment for which we would like to retrieve replies for |
Upon successful completion, the following response body is returned, which contains metadata about the comment and an array of objects each representing a child comment:
Response body:
{ "data": { // Comment metadata "id": 1591375845, "image_id": "FLWczwO", "comment": "https://i.imgur.com/pYtayj9.gifv", "author": "LeadBurrito", "author_id": 27434125, "on_album": true, "album_cover": "yYMX1E5", "ups": 51, "downs": 1, "points": 50, "datetime": 1551019039, "parent_id": 0, "deleted": false, "vote": null, "platform": "desktop", "children": [ // Comment children { "id": 1591446829, "image_id": "FLWczwO", "comment": "I hardly ever get there references on this show. Thank you for this", "author": "parallaxHero", "author_id": 32846870, "on_album": true, "album_cover": "yYMX1E5", "ups": 9, "downs": 0, "points": 9, "datetime": 1551028931, "parent_id": 1591375845, "deleted": false, "vote": null, "platform": "iphone", "children": [] }, { "id": 1591451041, "image_id": "FLWczwO", "comment": "https://i.imgur.com/O2pBe.gifv", "author": "SingingMeAndCthulioDownByRlyehFhtagn", "author_id": 554966, "on_album": true, "album_cover": "yYMX1E5", "ups": 7, "downs": 0, "points": 7, "datetime": 1551029426, "parent_id": 1591375845, "deleted": false, "vote": null, "platform": "iphone", "children": [] }, { "id": 1591474341, "image_id": "FLWczwO", "comment": "testing", "author": "testrapidapi", "author_id": 102369173, "on_album": true, "album_cover": "yYMX1E5", "ups": 1, "downs": 0, "points": 1, "datetime": 1551032485, "parent_id": 1591375845, "deleted": false, "vote": null, "platform": "desktop", "children": [] } ] }, "success": true, "status": 200 }
Code snippet:
const unirest = require('unirest'); const API_KEY = "YOUR_API°KEY"; const CLIENT_ID = "YOUR_CLIENT_ID"; unirest.get("https://imgur-apiv3.p.rapidapi.com/3/comment/1591375845/replies") .header("X-RapidAPI-Key", API_KEY) .header("Authorization", `Client-ID ${CLIENT_ID}`) .end(function (result) { console.log(JSON.stringify(result.body, null, 4)); });
That's It
You are ready to use the Imgur API to start analyzing the variety of images uploaded by its users. Feel free to use the code in your production applications and check out other awesome APIs on Rakuten RapidAPI to enhance your application even further.
About Rakuten RapidAPI
Rakuten RapidAPI is the world's largest API marketplace with 8,000+ third-party APIs and used by over 500,000 active developers. We enable developers to build transformative apps through the power of APIs. Find, test and connect to all the APIs you need in one place!
Check out some of the world's best public APIs including Microsoft, Sendgrid, Crunchbase, and Skyscanner.
Facebook | LinkedIn | Twitter
Body Worlds All Pictures Imgur
Source: https://blog.api.rakuten.net/top-10-best-image-apis-instagram-flickr-imgur/
0 Response to "Body Worlds All Pictures Imgur"
Post a Comment