{"_id":"550ada9e921b7d0d00228881","__v":18,"category":{"_id":"550ada9d921b7d0d0022887a","__v":2,"project":"550a379f635c660d00527fd8","version":"550ada9d921b7d0d00228876","pages":["550ada9e921b7d0d0022887f","550ada9e921b7d0d00228880","550ada9e921b7d0d00228881","5526826eb87cef230047be0e"],"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-03-19T02:55:05.573Z","from_sync":false,"order":4,"slug":"helpers-extras","title":"Helpers & Extras"},"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"},"project":"550a379f635c660d00527fd8","updates":["57095adc7e642f0e00e02997"],"next":{"pages":[],"description":""},"createdAt":"2015-03-19T03:01:03.023Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"auth":"required","params":[],"url":""},"isReference":false,"order":2,"body":"The events that are sent out on each Snoocore instance. \n\n# `access_token_expired`\n\nWhen using an OAuth type that can not refresh the access token ([Implicit based OAuth](doc:oauth-implicit), or [Explicit based OAuth](doc:oauth-explicit) with `duration: 'temporary'`) it is possible listen for this event to have the user re-authenticate with reddit.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"reddit.on('access_token_expired', function(responseError) {\\n  // do something, such as re-authenticating the user with reddit\\n});\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n# `access_token_refreshed`\n\nWhen using [Explicit based OAuth](doc:oauth-explicit)  with `duration: 'permanent'`, Snoocore will automatically refresh the access token. To know when this happens and get the new access token, listen to this event.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"reddit.on('access_token_refreshed', function(newAccessToken) {\\n  // do something with the new access token.\\n});\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n\n# `response_error`\n\nWhen we make a call with Snoocore and reddit responds with any HTTP error (4xx or 5xx errors), this event will be fired with relevant information.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"reddit.on('response_error', function(responseError) {\\n  \\n});\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nThis will be fired *every time* reddit responds with an HTTP error and does not account for Snoocore retrying endpoints. For example, if Snoocore retries an endpoint three times, fails the first two times (due to HTTP 5xx errors), and works the third time, this event will be fired twice.\n\n# `rate_limit`\n\nThis event is fired on every response from reddit that counts towards the applications rate limits and includes the current rate limit information:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"reddit.on('rate_limit', function(data) {\\n  // responds with the header data returned from reddit on\\n  // every response\\n  console.log(data.rateLimitUsed, \\n              data.rateLimitRemaining, \\n              data.rateLimitReset);\\n}); \",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nFor more information read the [official announcement](https://www.reddit.com/r/redditdev/comments/1yxrp7) for the rate limit headers.\n\n# `rate_limit_reached`\n\nFired when the rate limit has been reached.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"reddit.on('rate_limit_reached', function() {\\n  // oh no! rate limit reached!\\n});\\n\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"events","type":"basic","title":"Events"}
The events that are sent out on each Snoocore instance. # `access_token_expired` When using an OAuth type that can not refresh the access token ([Implicit based OAuth](doc:oauth-implicit), or [Explicit based OAuth](doc:oauth-explicit) with `duration: 'temporary'`) it is possible listen for this event to have the user re-authenticate with reddit. [block:code] { "codes": [ { "code": "reddit.on('access_token_expired', function(responseError) {\n // do something, such as re-authenticating the user with reddit\n});", "language": "javascript" } ] } [/block] # `access_token_refreshed` When using [Explicit based OAuth](doc:oauth-explicit) with `duration: 'permanent'`, Snoocore will automatically refresh the access token. To know when this happens and get the new access token, listen to this event. [block:code] { "codes": [ { "code": "reddit.on('access_token_refreshed', function(newAccessToken) {\n // do something with the new access token.\n});", "language": "javascript" } ] } [/block] # `response_error` When we make a call with Snoocore and reddit responds with any HTTP error (4xx or 5xx errors), this event will be fired with relevant information. [block:code] { "codes": [ { "code": "reddit.on('response_error', function(responseError) {\n \n});", "language": "javascript" } ] } [/block] This will be fired *every time* reddit responds with an HTTP error and does not account for Snoocore retrying endpoints. For example, if Snoocore retries an endpoint three times, fails the first two times (due to HTTP 5xx errors), and works the third time, this event will be fired twice. # `rate_limit` This event is fired on every response from reddit that counts towards the applications rate limits and includes the current rate limit information: [block:code] { "codes": [ { "code": "reddit.on('rate_limit', function(data) {\n // responds with the header data returned from reddit on\n // every response\n console.log(data.rateLimitUsed, \n data.rateLimitRemaining, \n data.rateLimitReset);\n}); ", "language": "javascript" } ] } [/block] For more information read the [official announcement](https://www.reddit.com/r/redditdev/comments/1yxrp7) for the rate limit headers. # `rate_limit_reached` Fired when the rate limit has been reached. [block:code] { "codes": [ { "code": "reddit.on('rate_limit_reached', function() {\n // oh no! rate limit reached!\n});\n", "language": "javascript" } ] } [/block]