{"_id":"55235488b4a0de0d00de800f","project":"550a379f635c660d00527fd8","user":"550a378e635c660d00527fd7","version":{"_id":"550ada9d921b7d0d00228876","forked_from":"550a3b2542fff40d00ae5ffb","project":"550a379f635c660d00527fd8","__v":3,"createdAt":"2015-03-19T14:18:05.245Z","releaseDate":"2015-03-19T14:18:05.245Z","categories":["550ada9d921b7d0d00228877","550ada9d921b7d0d00228878","550ada9d921b7d0d00228879","550ada9d921b7d0d0022887a","550ada9d921b7d0d0022887b","550ada9d921b7d0d0022887c","550ada9d921b7d0d0022887d","5523e61e71c0542100993493","55246f72ccc28a0d0062c560"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"3.0.0","version":"3.0.0"},"__v":32,"category":{"_id":"550ada9d921b7d0d00228879","version":"550ada9d921b7d0d00228876","__v":4,"pages":["550ada9e921b7d0d00228882","550ada9e921b7d0d00228883","550ada9e921b7d0d00228884","550ada9e921b7d0d00228885","55235488b4a0de0d00de800f","5523ceb87a46cc1700026b52","5523e1117a36b22b0088654b"],"project":"550a379f635c660d00527fd8","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-03-19T02:50:29.906Z","from_sync":false,"order":1,"slug":"getting-started","title":"Getting Started"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-04-07T03:52:40.256Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"auth":"required","params":[],"url":""},"isReference":false,"order":1,"body":"[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"If you are new to reddit development or JavaScript in general, skip this page and head to the to the [Beginners Guide](doc:beginners-guide) for a better introduction.\",\n  \"title\": \"Note\"\n}\n[/block]\nThe examples cover both Node.js & Browser JavaScript implementations. Both accomplish the same tasks:\n\n1. Get a users information [`GET /user/username/about` (link)](https://www.reddit.com/dev/api#GET_user_{username}_about)\n2. Get the [front page of a subreddit](https://www.reddit.com/dev/api#GET_hot) & navigate through the listing a bit (See [Listings](doc:listings)).\n\n## Requirements\n\nCreate a new implicit based application on reddit. Provide the details of the application into the code snippets below.\n\n## Node.js \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"var Snoocore = require('snoocore');\\n\\n/*\\n   Our new instance associated with a single account.\\n   It can take in various configuration options.\\n */\\nvar reddit = new Snoocore({\\n  // Unique string identifying the app\\n  userAgent: '/u/username myApp:::at:::3.0.0',\\n  // It's possible to adjust throttle less than 1 request per second.\\n  // Snoocore will honor rate limits if reached.\\n  throttle: 300,\\n  oauth: {\\n    type: 'implicit',\\n    key: '_sty7RuHMXLIfA',\\n    redirectUri: 'http://localhost:3000',\\n    // The OAuth scopes that we need to make the calls that we\\n    // want. The reddit documentation will specify which scope\\n    // is needed for evey call\\n    scope: [ 'identity', 'read', 'vote' ]\\n  }\\n});\\n\\n/*\\n   Prints a slice's children to stdout.\\n */\\nfunction printSlice(slice) {\\n  console.log('>>> Children in this slice', slice.children.length);\\n  slice.children.forEach(function(child) {\\n    console.log('[score: ' + child.data.score + '] ' + child.data.title);\\n  });\\n}\\n\\n// get information about a user\\nreddit('/user/kemitche/about').get().then(function(result) {\\n\\n  console.log(result); // information about a user account\\n\\n  // Use the listing helper to gracefully handle listings\\n  // Returns a promise for a slice -- a piece of a listing.\\n  return reddit('/r/thomasthedankengine/hot').listing({ limit: 5 });\\n}).then(function(slice) {\\n  printSlice(slice);   // First page children\\n  return slice.next(); // A promise for the next slice in the listing\\n}).then(function(slice) {\\n  printSlice(slice);   // Second page children\\n  console.log('done!');\\n}).catch(function(error) {\\n  console.error('oh no!', error.stack);\\n});\\n\",\n      \"language\": \"javascript\",\n      \"name\": null,\n      \"gist\": \"ccdbc19482fa259c13e7\"\n    }\n  ]\n}\n[/block]\n## Browser JavaScript\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<!doctype html>\\n<html>\\n  <head></head>\\n  <body>\\n    <script src=\\\"/path/to/snoocore/dist/Snoocore-browser.js\\\"></script>\\n    <script>\\n      var Snoocore = window.Snoocore; // grab instance from window\\n      /* Insert Node.js code abo here */\\n    </script>\\n  </body>\\n</html>\",\n      \"language\": \"html\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"success\",\n  \"title\": \"Finished!\",\n  \"body\": \"Jump to the [Basic Usage](doc:basic-usage) & [Configuration Options](doc:configuration-options) sections to get a better idea of the full features this library has to offer.\"\n}\n[/block]\n## Need more examples? \n\nThe  [Beginners Guide](doc:beginners-guide) walks through a complete (yet basic) application, and there is always more examples in the [examples repository](https://github.com/trevorsenior/snoocore-examples).","excerpt":"Basic calls and things.","slug":"quick-example","type":"basic","title":"Quick Example"}

Quick Example

Basic calls and things.

[block:callout] { "type": "info", "body": "If you are new to reddit development or JavaScript in general, skip this page and head to the to the [Beginners Guide](doc:beginners-guide) for a better introduction.", "title": "Note" } [/block] The examples cover both Node.js & Browser JavaScript implementations. Both accomplish the same tasks: 1. Get a users information [`GET /user/username/about` (link)](https://www.reddit.com/dev/api#GET_user_{username}_about) 2. Get the [front page of a subreddit](https://www.reddit.com/dev/api#GET_hot) & navigate through the listing a bit (See [Listings](doc:listings)). ## Requirements Create a new implicit based application on reddit. Provide the details of the application into the code snippets below. ## Node.js [block:code] { "codes": [ { "code": "var Snoocore = require('snoocore');\n\n/*\n Our new instance associated with a single account.\n It can take in various configuration options.\n */\nvar reddit = new Snoocore({\n // Unique string identifying the app\n userAgent: '/u/username myApp@3.0.0',\n // It's possible to adjust throttle less than 1 request per second.\n // Snoocore will honor rate limits if reached.\n throttle: 300,\n oauth: {\n type: 'implicit',\n key: '_sty7RuHMXLIfA',\n redirectUri: 'http://localhost:3000',\n // The OAuth scopes that we need to make the calls that we\n // want. The reddit documentation will specify which scope\n // is needed for evey call\n scope: [ 'identity', 'read', 'vote' ]\n }\n});\n\n/*\n Prints a slice's children to stdout.\n */\nfunction printSlice(slice) {\n console.log('>>> Children in this slice', slice.children.length);\n slice.children.forEach(function(child) {\n console.log('[score: ' + child.data.score + '] ' + child.data.title);\n });\n}\n\n// get information about a user\nreddit('/user/kemitche/about').get().then(function(result) {\n\n console.log(result); // information about a user account\n\n // Use the listing helper to gracefully handle listings\n // Returns a promise for a slice -- a piece of a listing.\n return reddit('/r/thomasthedankengine/hot').listing({ limit: 5 });\n}).then(function(slice) {\n printSlice(slice); // First page children\n return slice.next(); // A promise for the next slice in the listing\n}).then(function(slice) {\n printSlice(slice); // Second page children\n console.log('done!');\n}).catch(function(error) {\n console.error('oh no!', error.stack);\n});\n", "language": "javascript", "name": null, "gist": "ccdbc19482fa259c13e7" } ] } [/block] ## Browser JavaScript [block:code] { "codes": [ { "code": "<!doctype html>\n<html>\n <head></head>\n <body>\n <script src=\"/path/to/snoocore/dist/Snoocore-browser.js\"></script>\n <script>\n var Snoocore = window.Snoocore; // grab instance from window\n /* Insert Node.js code abo here */\n </script>\n </body>\n</html>", "language": "html" } ] } [/block] [block:callout] { "type": "success", "title": "Finished!", "body": "Jump to the [Basic Usage](doc:basic-usage) & [Configuration Options](doc:configuration-options) sections to get a better idea of the full features this library has to offer." } [/block] ## Need more examples? The [Beginners Guide](doc:beginners-guide) walks through a complete (yet basic) application, and there is always more examples in the [examples repository](https://github.com/trevorsenior/snoocore-examples).