Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does this gem support the "save" scope? #47

Closed
onebree opened this issue Mar 5, 2017 · 3 comments
Closed

Does this gem support the "save" scope? #47

onebree opened this issue Mar 5, 2017 · 3 comments
Labels

Comments

@onebree
Copy link

onebree commented Mar 5, 2017

I want to be able to retrieve a user's saved posts/comments (see app)

Does this gem offer such capability? I was thinking of using RedditKit, but as listed here, it does not support OAuth. However, I plan to use omniauth-reddit for signing in users to my app.

Thank you.

@avinashbot
Copy link
Owner

Yes it does! Here's the relevant method on the github documentation. There are a few things you have to keep in mind if you want to go through a user's saved posts history:

  1. Redd can't fetch all the saved posts in one call and must basically traverse through the pages (like on the website). I whipped up a script that lets me go through my entire post history below for reference.
  2. Reddit won't allow anyone to go more than 1000 posts back, even if I've saved more than 1000 posts. Although I did notice that when I delete some saved posts, it lets me go further back through my history.
  3. Going back to point 1, fetching 1000 posts required 10 100-post calls, which mean Redd waits for 9 seconds, since Redd has built-in rate limiting. Redd uses Kernel#sleep, which would stop your web server for some time. You can mitigate this issue by either disabling rate limiting entirely (which is not in line with reddit's API rules) or running the calls asynchronously. (I should probably get around to documenting this, since the gem is probably going to be used a lot with Rails).

And here's that script:

all_saved = []
after = nil
loop do
  # Get all posts after the post in the 'after' variable
  results = reddit.me.saved(after: after, limit: 100)
  puts "Fetched #{results.count} posts."
  # Store the fetched results
  all_saved.concat(results)
  # Keep track of what post to get the saved posts after
  after = results.after
  # If after was nil, we've reached the end.
  break if after.nil?
end

puts all_saved.length # => 938 # reddit is limiting me to 938 posts

@onebree
Copy link
Author

onebree commented Mar 5, 2017

@avinashbot Wow! Thank you for the explanation and script! I didn't know about the 1000 post limit, either. Is that also the case for the Reddit website? (I have around 950 saves, so I'm not sure.)

The only workaround I see (for my app in particular) to the 1K posts issue is... If I store each post in my own database, and every time the user syncs up, the saved count goes up past 1K if needed. But that assumes a user has under 1K posts to begin with... (I am preparing the migrations for this approach just for a deadline for class, but am still unsure whether I should do this, as I'd be documenting the entirety of reddit almost.)

@avinashbot
Copy link
Owner

Yep, a thousands posts is the limitation for every type of listing on the website. It is annoying, since my saves only go back 2 years and I'd like to look at posts I've saved earlier than that.

Storing user's posts seems to be the only safe option, but at least you'll only need to save the object's fullname (by calling name on the comment or submission) and you can look it up later with the from_id method.

Hope that was helpful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants