title: TypeError: Cannot read property 'state' of undefined
body: <h2>Error</h2>
  
  <pre><code>/Users/sharanduggirala/Documents/UID/CS235ProjectJS/node_modules/reddit-oauth/lib/index.js:278t-development-environment@1.0.0~preinstall: javascript-development-environment@1.0.0
          if (query.state !== state || !query.code) {
                   ^
  
  TypeError: Cannot read property 'state' of undefined
      at RedditApi__oAuthTokens [as oAuthTokens] (/Users/sharanduggirala/Documents/UID/CS235ProjectJS/node_modules/reddit-oauth/lib/index.js:278:18)
      at Object.&lt;anonymous&gt; (/Users/sharanduggirala/Documents/UID/CS235ProjectJS/buildScripts/srcReddit.js:30:8)
      at Module._compile (module.js:624:30)
      at loader (/Users/sharanduggirala/Documents/UID/CS235ProjectJS/node_modules/babel-register/lib/node.js:144:5)
      at Object.require.extensions.(anonymous function) [as .js] (/Users/sharanduggirala/Documents/UID/CS235ProjectJS/node_modules/babel-register/lib/node.js:154:7)
      at Module.load (module.js:545:32)
      at tryModuleLoad (module.js:508:12)
      at Function.Module._load (module.js:500:3)
      at Function.Module.runMain (module.js:665:10)
      at /Users/sharanduggirala/Documents/UID/CS235ProjectJS/node_modules/babel-cli/lib/_babel-node.js:159:24
  </code></pre>
  
  <hr>
  
  <h2>Code</h2>
  
  <p>I am currently trying to use the <a href="https://www.reddit.com/dev/api/" rel="nofollow noreferrer">Reddit API</a>, and am trying to get the example on <a href="https://www.npmjs.com/package/reddit-oauth" rel="nofollow noreferrer">this</a> page to work. This is the error that I got when trying to compile the code below: </p>
  
  <pre><code>var RedditApi = require('reddit-oauth');
  var request = require('request');
  
  var reddit = new RedditApi({
      app_id: **********,
      app_secret: ********* ,
      redirect_uri: 'http://localhost:8888'
  });
  
  // Authenticate with username/password
  reddit.passAuth(
      'sharan100',
      '********',
      function (success) {
          if (success) {
              // Print the access token we just retrieved
              console.log(reddit.access_token);
          }
      }
  );
  
  // Get the OAuth URL to redirect users to
  // Scopes are defined here: https://github.com/reddit/reddit/wiki/OAuth2
  reddit.oAuthUrl('some_state', 'identity');
  
  // After the user is redirected back to us, grab the query string
  // object and exchange it for a set of access and refresh tokens.
  // Scope has to be identical as the one provided to oAuthUrl. Can
  // change for each authentication attempt.
  reddit.oAuthTokens(
      'some_state',
      request.query,
      function (success) {
          // Print the access and refresh tokens we just retrieved
          console.log(reddit.access_token);
          console.log(reddit.refresh_token);
      }
  );
  </code></pre>
  
  <hr>
  
  <h2>Request</h2>
  
  <p>The output of <code>console.log('request')</code> is: </p>
  
  <pre><code>{ [Function: request]
    get: [Function],
    head: [Function],
    options: [Function],
    post: [Function],
    put: [Function],
    patch: [Function],
    del: [Function],
    delete: [Function],
    jar: [Function],
    cookie: [Function],
    defaults: [Function],
    forever: [Function],
    Request:
     { [Function: Request]
       super_:
        { [Function: Stream]
          super_: [Object],
          Readable: [Object],
          Writable: [Object],
          Duplex: [Object],
          Transform: [Object],
          PassThrough: [Object],
          Stream: [Circular],
          _isUint8Array: [Function: isUint8Array],
          _uint8ArrayToBuffer: [Function: _uint8ArrayToBuffer] },
       debug: undefined,
       defaultProxyHeaderWhiteList:
        [ 'accept',
          'accept-charset',
          'accept-encoding',
          'accept-language',
          'accept-ranges',
          'cache-control',
          'content-encoding',
          'content-language',
          'content-location',
          'content-md5',
          'content-range',
          'content-type',
          'connection',
          'date',
          'expect',
          'max-forwards',
          'pragma',
          'referer',
          'te',
          'user-agent',
          'via' ],
       defaultProxyHeaderExclusiveList: [ 'proxy-authorization' ] },
    initParams: [Function: initParams],
    debug: [Getter/Setter] }
  </code></pre>
  
  <p><strong>Note</strong>: Code has been edited to reflect the comments below. </p>
  
  <hr>
  
  <p>Not sure why this code seems to be getting the errors above. </p>