Reddit API

Developer
Size
4,397 Kb
Views
18,216

How do I make an reddit api?

Learning Javascript/jQuery using APIs. Display Reddit posts into masonry layout.. What is a reddit api? How do you make a reddit api? This script and codes were developed by Juan Vargas on 14 October 2022, Friday.

Reddit API Previews

Reddit API - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Reddit API</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
<body> <div class="top"> <ul> <li><i class="fa fa-reddit"></i></li> <li>Reddit API</li> <li class="right"><a href="https://dribbble.com/Festus911"><i class="fa fa-dribbble"></i></a></li> <li class="right"><a href="https://twitter.com/FESTUS911"><i class="fa fa-twitter"></i></a></li> </ul>
</div> <div class="menu"> <ul> <li class="active"><a>Home</a></li> <li class="subreddits"></li> <li class="right"><a><i class="fa fa-bars"></i></a></li> </ul> </div> <div class="message_holder"> <div class="message"></div> </div>
<div class="container" > <!--h3>To do</h3> <ul> <li>Masonry Layout or Timeline Layout [List/Grid]</li> <li>Add Trigger to load next set of posts with Infinite Scrolling Plugin</li> <li>Detect all imgur images which don't have an extension (png, jpg, gif)</li> <li style="text-decoration:line-through">Find Subreddits</li> <li style="text-decoration:line-through">Points, Comments, Author, Permalink</li> <li>Include text-only posts</li> <li>Add lightbox (colorbox plugin)</li> <li>Anything else...</li> </ul> <hr-->
<div id="posts" ></div>
</div>
</body> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='https://rawgithub.com/desandro/masonry/v2.1.08/jquery.masonry.js'></script>
<script src='https://imagesloaded.desandro.com/imagesloaded.pkgd.js'></script> <script src="js/index.js"></script>
</body>
</html>

Reddit API - Script Codes CSS Codes

body { background:#f0f0f0; padding:0px; margin:0px; font-family:Arial; font-size:13px; color:#777;
}
ul li { list-style-type:circle;
}
h1,h2,h3,h4,h5 { margin:0px; padding:0px;
}
pre { white-space: pre-line;
}
p { line-height:25px; margin:0px;
}
a { cursor:pointer; text-decoration:none;
}
.menu { background:#2B3D4F; height:60px;
}
.menu ul { width:980px; margin:0px auto; padding:0px;
}
.menu ul li{ float:left; list-style:none; display:inline;
}
.menu ul li.right{ float:right; font-size:21px;
}
.menu ul li.right i{ color:gray;
}
.menu ul li.active a{ color:#FFF;
}
.menu ul li a{ height:60px; line-height:60px; padding:0 10px; display:block; color:#a2bdd9; text-transform:capitalize;
}
.menu ul li a:hover{ color:dodgerblue;
}
.container { width:980px; margin: 0 auto; margin-top:20px; position:relative; height;100%;
}
.container #posts .post { width:280px; margin: 0 18px 18px 0; float:left; padding:12px; background: #fff; border: solid 1px #ececec; border-radius:3px; float: left;
}
.container #posts .post.video {	border-color:coral;
}
.container #posts .post.imgur {	border-color:lightseagreen;
} .container #posts .post.thumbnail {	border-color:dodgerblue;
}
.container #posts .post.self {	border-color:orange;
}
.container #posts .post.API { border-color:red;
}
.container #posts .post img { max-width:100%;
}
.container #posts .post p{
line-height: 24px;
font-size: 14px;
color: #555;
font-weight: 400;
}
.container #posts .post img { max-width:100%;
}
.top{ background: #2981B9;
}
.top ul{ margin: 0px auto; height: 80px; width: 980px; padding: 0px;
}
.top ul li{ height: 80px; line-height: 80px; list-style: none; float: left; color: white; margin-right: 10px;
}
.top ul li.logo a { color:white; text-decoration:none; font-size:14px;
}
.top ul li.right{ float:right;
}
.top ul li i{ color: white; font-size: 22px; line-height:40px;
}
.post span { padding: 10px; position: relative; left: -6px; bottom: -6px;
}
.info_bar { margin:0px; padding:0px; display:inline-block; width:100%; margin-top:10px;
}
.info_bar li,.info_bar a{ float:left; list-style:none; background: #eee; padding: 6px 8px; display: inline-block; color: grey; margin-right:5px; border-radius:2px;
}
.info_bar a.readmore{	background:lightseagreen; color:white;
}
.info_bar li span { margin-left:5px;
}
.info_bar li i { margin-right:6px;
}
.embedly-embed { width:280px; height:auto;
}
.message_holder { background:#fdfdfd; border-bottom:solid 1px #ddd;
}
.message_holder .message {	width:980px; height:45px; line-height:45px; margin:0 auto;
}

Reddit API - Script Codes JS Codes

//Post with green border - Retrived using imgurAPI
//Post with red/orange border - Retrived using embedd.ly API
//Retrieve Reddits for future filtering
$.getJSON("http://www.reddit.com/reddits.json?jsonp=?&limit=10", function(data) { $.each(data.data.children, function(i, item) { var subs = $("<a>").attr("href", item.data.display_name).html(item.data.display_name); var list = $("<li class='subreddits'>").append(subs); $(".menu ul").append(list); });
});
//Get Subreddit Information
$.getJSON("http://www.reddit.com/r/funny.json?jsonp=?&show=all&limit=100", function(data) { $.each(data.data.children, function(i, item) { //Retrieve Number of Comments var comments = $("<li>").html("<i class='fa fa-comments-o'></i>" + item.data.num_comments); //Retrieve author username var author = $("<p>").text(item.data.author); //Retrieve points var points = $("<li>").html("<i class='fa fa-arrow-up'></i>" + item.data.score); //Get Reddit Post paermalinks var permalink = $("<a class='readmore'>").attr("href", "http://www.reddit.com" + item.data.permalink).html("Read more"); //Get Reddit Post Titles var title = $("<p>").text(item.data.title); //Statistics bar var stats = $("<ul class='info_bar'>").append(points, comments, permalink); //Put link into image var images = $("<img/>").attr("src", item.data.url); //Create Thumbnail var thumbnail = $("<img/>").attr("src", item.data.thumbnail); //Pull post text content var body = $("<p>").html(item.data.selftext_html).text(); //Retrieve iframe embed content var embeded_content = $("<p>").html(item.data.media_embed.content).text(); IsValidImageUrl(item.data.url, function(url, isvalid) { if (isvalid) { var post = $("<div class='post'>").append(images, title, stats).appendTo("#posts"); } else if (item.data.domain == "imgur.com") { //imgur API var clientId = "94330720455974e"; var imgurID = $('<a>', {href: item.data.url})[0].pathname.replace(/\.(.+)$/, ''); $.ajax({ url: 'https://api.imgur.com/3/image/' + imgurID, type: 'GET', beforeSend: function(request) { request.setRequestHeader('Authorization', 'Client-ID 94330720455974e'); }, datatype: 'json', success: function(data) { var newimage = $("<img/>").attr("src", data.data.link); var newpost = $("<div class='post imgur'>").append(newimage, title, stats).appendTo("#posts"); } }); } else if (item.data.secure_media.oembed.type == "video") { //Embed.ly API Key var key = '1ce631f8323d443094588475b2988052'; //Decode encoded URL var url_decode = decodeURIComponent(item.data.secure_media.oembed.thumbnail_url, key); //Remplace &amp; with & var url_ready = $("<p>").html(url_decode).text(); //Get YouTube Thumbnail var video_thumbnail = $("<img/>").attr("src", url_ready); //Append image to box var thumbnail_post = $("<div class='post video'>").append(video_thumbnail, title, stats).appendTo("#posts"); //Display YouTube Video //var videopost = $("<div class='post'>").text(item.data.title).append(embeded_content).append(stats); } else if (item.data.is_self == true) { var selfpost = $("<div class='post self'>").append(title, body, stats).appendTo("#posts"); } else { var thumbpost = $("<div class='post thumbnail'>").append(title, thumbnail, stats).appendTo("#posts"); } }); }); //Start calling Masonry var $container = $('#posts'); $container.imagesLoaded(function() { $container.masonry({ itemSelector: '.post' }); }); //End of Calling Masonry
});
function IsValidImageUrl(url, callback) { var img = new Image(); img.onerror = function() { callback(url, false); }; img.onload = function() { callback(url, true); }; img.src = url;
}
Reddit API - Script Codes
Reddit API - Script Codes
Home Page Home
Developer Juan Vargas
Username juanv911
Uploaded October 14, 2022
Rating 3.5
Size 4,397 Kb
Views 18,216
Do you need developer help for Reddit API?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Juan Vargas (juanv911) Script Codes
Create amazing SEO content with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!