Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
An example of a retrieving data from reddit's JSON(p) api using jquery
<!DOCTYPE html>
<!--
Stuart Powers
http://sente.cc/
http://twitter.com/stuartpowers
-->
<html>
<head>
<script src="http://j.mp/jqymin"></script>
</head>
<body>
<div id="reddit-content">
</div>
<script>
$.getJSON(
"http://www.reddit.com/r/pics.json?jsonp=?",
function foo(data)
{
$.each(
data.data.children.slice(0, 10),
function (i, post) {
$("#reddit-content").append( '<br>' + post.data.title );
$("#reddit-content").append( '<br>' + post.data.url );
$("#reddit-content").append( '<br>' + post.data.permalink );
$("#reddit-content").append( '<br>' + post.data.ups );
$("#reddit-content").append( '<br>' + post.data.downs );
$("#reddit-content").append( '<hr>' );
}
)
}
)
.success(function() { alert("second success"); })
.error(function() { alert("error"); })
.complete(function() { alert("complete"); });
</script>
</body>
</html>
@pklopping

This comment has been minimized.

Copy link

@pklopping pklopping commented Jul 25, 2013

I have been searching for far too long to figure out how to do this. Thanks!

@difficultashish

This comment has been minimized.

Copy link

@difficultashish difficultashish commented Jan 1, 2014

Hi, is there an example of trying to access the login API using jQuery? I tried using JSONP and changing the URL to "http://www.reddit.com/api/login?jsonp=?&user=LittleGlobalVillage&passwd=22091988", but that gives a 404. Any hint what I am doing wrong?

The wrappers available are only available in node.js and not in JS/jQuery.

@sente

This comment has been minimized.

Copy link
Owner Author

@sente sente commented Jan 24, 2014

@pklopping, welcome! (I didn't see your 6-month comment until a minute ago, whoops...)

@hexadeciman

This comment has been minimized.

Copy link

@hexadeciman hexadeciman commented Feb 14, 2014

Same as @difficultashish I can't figure out how to use the login api .. can someone a simple example on how to achieve a login with an http post request ?

@BenjaminAdams

This comment has been minimized.

Copy link

@BenjaminAdams BenjaminAdams commented Jul 12, 2014

If you want the capability to have your users login/upvote you can use the widget at http://embed.redditjs.com

@kaiyuandeng

This comment has been minimized.

Copy link

@kaiyuandeng kaiyuandeng commented Aug 31, 2014

how come you don't need to send a modhash or some other verification token?

@Trudelgy

This comment has been minimized.

Copy link

@Trudelgy Trudelgy commented Apr 16, 2015

how could i make it display the description of a post?

@alexweininger

This comment has been minimized.

Copy link

@alexweininger alexweininger commented Jul 23, 2015

How could I make it so it makes a seperate div for each post ?

@carlskeel

This comment has been minimized.

Copy link

@carlskeel carlskeel commented Oct 7, 2015

I have put it in a div called id of #reddit-content and I get the data in there but for some reason it makes the scroll box way too large.

@jbat04

This comment has been minimized.

Copy link

@jbat04 jbat04 commented Dec 7, 2016

Thank you!! have been looking for this for a while

@thesheetal

This comment has been minimized.

Copy link

@thesheetal thesheetal commented Aug 23, 2017

It works :) Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment