jzelinskie / geddit Goto Github PK
View Code? Open in Web Editor NEWgolang reddit api wrapper
License: BSD 3-Clause "New" or "Revised" License
golang reddit api wrapper
License: BSD 3-Clause "New" or "Revised" License
Hardcoded http.DefaultClient
prohibits the user from specifying custom timeouts, setting custom cookies etc. Especially the lack of timeouts is deadly as the default client never times out.
Getting a redditor's submissions only return 100 submissions only meanwhile there are more.
so the solution is a loop running requests using after parameter
https://www.reddit.com/user/redditor/submitted.json?limit=1000&after=
Reddit now supports TLS, we should probably use it by default in all the URL literals.
The Listing function asks for an After options but the go API doesn't provide a way to get the After value.
I mean this as opposed to using api.reddit.com/id.
Of course, I'm not sure how useful this is anyway with regard to the new Oauth requirement.
Forked the repo, cloned it, get the following upon running "go test":
--- FAIL: TestSubmit (1.08s)
reddit_test.go:26: false
reddit_test.go:53: failed to submit
reddit_test.go:58: failed to submit
FAIL
exit status 1
FAIL github.com/joshuathompson/geddit 1.866s
Apparently due to rate limits: "you are doing that too much. try again in x minutes.". It appears after a little research that maybe new accounts or accounts with no karma have stricter limitations.
From subreddit.go#21
type Subreddit struct {
[...]
DateCreated float32 `json:"created_utc"`
[...]
}
DateCreated float32
is to small for the timestamps the Reddit APi provides. Example:
1478970533
1.4789705e+09
which is 1478970500
Which is 33 sec difference! I'd suggest to use int32
(-2147483648 to 2147483647) or uint32
(0 to 4294967295; since its a unix timestamp we wont need negative values).
However, since this repo hasn't been updated for a year now I have low hopes this will be changed. Nevertheless - I like the simplicity of geddits approach and its totally sufficient for my needs.
I was wondering if there could be a feature to get a slice of Comment
pointers from a subreddit directly, instead of a particular Submission
. For example, if you go to reddit.com/r/golang/comments, you'll see all the comments posted in the subreddit, irrespective of the post.
This makes it easier to access all the comments if I were to build a bot, rather than looping through all the posts' comments and their replies.
// SavedComments fetches comments saved by given username using OAuth.
func (o *OAuthSession) SavedComments(user string, params ListingOptions) ([]*Comment, error) {
var s interface{}
url := fmt.Sprintf("https://oauth.reddit.com/user/%s/saved", user)
err := o.getBody(url, &s)
if err != nil {
return nil, err
}
helper := new(helper)
helper.buildComments(s)
return helper.comments, nil
}
As you can see above, the function takes in the variable params
, but doesn't actually use it in the url, like the Listing function does with these lines.
p, err := query.Values(params)
if err != nil {
return nil, err
}
url := fmt.Sprintf("https://oauth.reddit.com/user/%s/%s?%s", username, listing, p.Encode())
This means that for example using the After
listing option to actually get more than five saved comments is not possible.
I might try fixing this myself, if I found out how to locally develop go modules.
When I run the code from the Example(url) given on the godoc page it tells me to visit a reddit url. When I click on the link a browser window opens saying that I broke reddit. I'm running Ubuntu 22.
The line in the code that sets the UserAgent on Reply requests is commented out. Why?
... wish there was better ways to socially interact with a repo than the issues tracker... but I just wanted to express my thanks for the code! Has enabled me to jump right into hacking on a little idea I had for a reddit bot.
I will take a look at OAuth support if someone else isn't already poking at it.
We're currently using a slapped together implementation to fetch comments from reddit.com. I'd like to completely model the whole thing out using static types and just encoding/json.Unmarshal() the whole thing. A lot of the complexity around the type hierarchy needed to parse the JSON can be hidden by struct embedding.
However, the "replies" field on comments either returns a list of objects or empty string if there are none. Sadly, I think this will require some kind of run-time type assertion.
Does geddit has OAuth2 Support? Currently, I'm using I with plaintext username and password.
I'm getting this error when calling session.Frontpage since one of the last commits, where apparently float64 was replaced by uint32 in some structures.
Deleting a submission, it is being removed from reddit, but the Delete method returns error: Failed to delete item
Small thing, but lines 38-40
func (c Comment) String() string {
return fmt.Sprintf("%s (%d/%d): %s", c.Author, c.UpVotes, c.DownVotes, c.Body)
}
Probably should be like this:
func (c Comment) String() string {
return fmt.Sprintf("%s (%.0f/%.0f): %s", c.Author, c.UpVotes, c.DownVotes, c.Body)
}
Atm it prints out float64=number, which is kind hard to read :)
The OAuth token usually expires after an hour. Can there be a way to refresh tokens automatically?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.