not-an-aardvark / snoowrap

A JavaScript wrapper for the reddit API
MIT License
1.01k stars 125 forks source link

Unable to get it working on the browser #369

Open ahron1 opened 1 year ago

ahron1 commented 1 year ago

I am trying to use snoowrap in a browser-only setup.

I created a new installed app on https://ssl.reddit.com/prefs/apps/ and got an app id.

Since I don't need user context (I just need to do things that a logged-out user can do), I am using fromApplicationOnlyAuth.

I included the minified script. My javascript looks something like this:

const snoowrap = window.snoowrap;
snoowrap.fromApplicationOnlyAuth({
  userAgent: 'xxxx',
  clientId: 'xxxxxyyyyyyzzzzzzz',
  deviceId: 'DO_NOT_TRACK_THIS_DEVICE',
  grantType: snoowrap.grantType.INSTALLED_CLIENT,
  permanent: true
}).then(r => {
  // Now we have a requester that can access reddit through a "user-less" Auth token
  return r.getHot().then(posts => {
    // do something with posts from the front page
    console.log(posts);
  });
})

For userAgent I have the name of the app, clientId I got from reddit while creating the app.

I get an error like

Uncaught TypeError: Cannot read properties of undefined (reading 'fromApplicationOnlyAuth')

Based on the documentation here, I am not sure what I am missing, so any help on how to get in working on the browser would be much appreciated.