vartanbeno / go-reddit Goto Github PK
View Code? Open in Web Editor NEWGo library for accessing the Reddit API.
License: Other
Go library for accessing the Reddit API.
License: Other
I'm looking for the markdown image implementation trying to find if there are any controls for sizing the image. Is there some documentation I've been overlooking? Or should I look through the fyne markdown processing to find image and any sizing that might be implemented?
Should I be happy finding https://github.com/fyne-io/fyne/blob/master/widget/markdown_test.go and that there is no sizing in _test and markdown.go so maybe it doesn't exist?
Any help is much appreciated!
It seems that go-reddit has progressed a lot since version 1.0.0, which is the version automatically downloaded when using go modules. Could you push another release? It has been over a 100 commits since 1.0.0 was release.
Unluckily, #18 did not help me. 2FA is disabled, I triple checked my username/password/ID/secret but I still get the error
Get "https://oauth.reddit.com/r/itookapicture/top?limit=1&t=today": oauth2: server response missing access_token
{
"Method":"GET",
"URL":"*net/url.URL"{
"Scheme":"https",
"Opaque":"",
"User":"*net/url.Userinfo nil",
"Host":"oauth.reddit.com",
"Path":"/r/itookapicture/top",
"RawPath":"",
"ForceQuery":false,
"RawQuery":"limit=1&t=today",
"Fragment":"",
"RawFragment":""
},
"Proto":"HTTP/1.1",
"ProtoMajor":1,
"ProtoMinor":1,
"Header":"net/http.Header"[
"Content-Type":[
"application/x-www-form-urlencoded"
],
"Accept":[
"application/json"
]
],
"Body":"io.ReadCloser nil",
"GetBody":"nil",
"ContentLength":0,
"TransferEncoding":[]"string len":0,
"cap":0,
"nil",
"Close":false,
"Host":"oauth.reddit.com",
"Form":"net/url.Values nil",
"PostForm":"net/url.Values nil",
"MultipartForm":"*mime/multipart.Form nil",
"Trailer":"net/http.Header nil",
"RemoteAddr":"",
"RequestURI":"",
"TLS":"*crypto/tls.ConnectionState nil",
"Cancel":"<-chan struct"{
}"nil",
"Response":"*net/http.Response nil",
"ctx":context.Context(*context.emptyCtx) *0
}
I noticed that the User
field is nil
. Is that the intended behavior? I'm initializing the client like this:
id := "xxxxxxxxxxxx"
secret := "xxxxxxxxxxxx"
user := "xxxxxxxxxxxx"
password := "xxxxxxxxxxxx"
credentials := reddit.Credentials{ID: id, Secret: secret, Username: user, Password: password}
client, err := reddit.NewClient(credentials)
if err != nil {
panic(err)
}
posts, _, err := client.Subreddit.TopPosts(context.Background(), "itookapicture", &reddit.ListPostOptions{
ListOptions: reddit.ListOptions{
Limit: 1,
},
Time: "today",
})
if err != nil {
panic(err)
}
I tried to track down where this error comes from and the call stack seems to be:
reddit#Do:348
reddit#DoRequestWithClient:437
client#Do:593
client#do:???
but I have no clue where inside client#do
the error happens (set breakpoints at every return
but they don't trigger). Thus, I am not quite sure if this is caused by misuse on my end, an error in go-reddit
or (rather unlikely) in client.go
.
Howdy All y'all,
I'm looking for a little help in how to avoid the "badger badger" or "Blocked" issue that comes when using a golang version > 16 with go-reddit. Here is some background information:
I'm hoping that someone will lend me a hand crafting my normal call to this API:
sr, _, err := reddit.DefaultClient().Subreddit.Get(ctx, subreddit)
and turn off TLS.
Any help you can provide is very much appreciated!
Hi,
Can you add a field in Post that contains all media present in reddit Post (reddit returns a field called "media_metadata")
thanks
Whenever I try to download go-reddit using the command go get github.com/vartanbeno/go-reddit
, I get the following error: package github.com/vartanbeno/go-reddit: no Go files in /home/<username>/go/src/github.com/vartanbeno/go-reddit.
I've tried about every fix that I can think of, including reinstalling go a couple times. I am running Ubuntu 20.04, GNU/Linux 5.4.0-58-generic. I am able to install other packages from Github.
When making an api call, if reddit reports there's no rate limit left (ie: you just used up the last api call for the 10 minute period), the library doesn't bother building a response using the response body, instead short circuiting out with a RateLimitError.
It checks the response, but if there is a header from the reddit api saying there's no rate limit remaining, it will return an error. See here:
https://github.com/vartanbeno/go-reddit/blob/master/reddit/reddit.go#L450
It will return an empty response object, without reading any response body from the reddit api, which is a bug. See here:
https://github.com/vartanbeno/go-reddit/blob/master/reddit/reddit.go#L366
It should only return an empty response body if there's no body from reddit. As the rate limit is reduced by each api call for the 10 minute period, the last api call will incorrectly return an error.
WithCredentials not declared by package reddit
I did can't find WithCredentials
in doc page.
Is the README.md not update timely?
Would it be possible to add authentication with scopes? I'm pretty sure I need the modposts
scope in order to delete posts, because right now I keep getting 403 Forbidden errors.
if I were to spam call subreddit.NewPosts(), will the method just block as nessecary to skirt just under reddit's rate limit, or will it just return any rate limit errors
if i want go subreddit: https://www.reddit.com/r/btc/search
btc, all data.
client.Subreddit.SearchPosts(ctx, "", "btc", &reddit.ListPostSearchOptions{
ListPostOptions: reddit.ListPostOptions{
ListOptions: reddit.ListOptions{
Limit: limit,
After: after,
},
},
})
i got empty []. but in https://www.reddit.com/r/btc/search has datas.
Seems as though the godoc shows the latest version as v1.0.0. Is there a way to fix this?
Howdy all y'all,
I'm trying to find and display a post's header image.
Is this a good place to look for it?
posts, resp, err = cl.Subreddit.TopPosts(ctx, subreddit, &reddit.ListPostOptions{
ListOptions: reddit.ListOptions{
Limit: maxRedditItems,
After: respAfter,
},
Time: "all",
})
var thePosts []*reddit.Post = nil
for _, post := range posts {
lastByByte := strings.ToLower(post.URL[len(post.URL)-4:])
if (lastByByte == ".jpg") || (lastByByte == ".png") {
log.Println("URL is an image:", post.URL)
} else {
log.Println("URL is NOT an image:", post.URL)
}
thePosts = append(thePosts, post)
}
Thanks for any help!
Dale
Currently go-reddit uses the default error type in Go, which is just an interface with a string attribute. It would be helpful to create a custom error type that included more specific information such as response code or the specific ENUM error type.
For some reason I can't access these? Weird, cause reddit.NewClient
works
$ mkdir repro-go-reddit-bug
$ cd repro-go-reddit-bug
$ go mod init github.com/bbkane/repro-go-reddit-bug
$ go get github.com/vartanbeno/go-reddit
Contents of go.mod
:
$ cat go.mod
module github.com/bbkane/repro-go-reddit-bug
go 1.15
require github.com/vartanbeno/go-reddit v1.0.0
Add the following main.go
:
$ cat main.go
package main
import "github.com/vartanbeno/go-reddit/reddit"
func main() {
_, _ = reddit.NewReadonlyClient()
}
$ go run main.go
# command-line-arguments
./main.go:6:9: undefined: reddit.NewReadonlyClient
$ go version
go version go1.15.1 darwin/amd64
func run() (err error) {
credentials := reddit.Credentials{ID: "", Secret: "", Username: "", Password: ""}
client, err := reddit.NewClient(credentials)
if err != nil {
return
}
vote, err := client.Post.Upvote(context.Background(), "t3_ig9u4z")
if err != nil {
return err
}
fmt.println(vote)
return
}
What happened to the 2.0.0 release?
The checksum has changed. Has this release been compromised?
https://github.com/marcofranssen/gothermostat/pull/121/checks?check_run_id=3717744193#step:5:6
When I tried, the bellow code i got 403 error, Can any one tell me why this is happening and how can I fix this issue?
package main
import (
"context"
"fmt"
"github.com/vartanbeno/go-reddit/v2/reddit"
)
func main() {
ctx := context.Background()
client, err := reddit.NewReadonlyClient()
if err != nil {
fmt.Println("Error from reddit.NewReadonlyClient()", err)
}
listOpts := &reddit.ListOptions{
Limit: 10, // always 100, so we can filter out without extra logic; if this is ever > 100, use resp.After
}
data, res, err := client.Subreddit.HotPosts(ctx, "AnimalsBeingBros", listOpts)
fmt.Println(data)
fmt.Println(res)
fmt.Println(err)
}
I need to retrieve a user description, but I did not find anything in the docs about it.
It would be nice feature.
This is how its done in praw https://www.reddit.com/r/redditdev/comments/j3atzn/is_there_a_way_to_retrieve_description_of_a_user/
@vartanbeno I've noticed there's a lack of activity on your account and this repository. Is this still maintained?
I can't seem to get a basic auth going using Client ID, Client Secret, Username and Password. Any ideas why? I verified and I'm 100% sure I'm setting the right values.
title
I'm facing issues authenticating for a simple OverviewOf query.
I created the API app in my account ("script" type) and registered it for Reddit API usage, but I cannot seem to get it to authenticate correctly. I'm wondering if it might have to do with MFA.
Here is a snippet to reproduce the issue along with its output:
package main
import (
"context"
"fmt"
"log"
"github.com/vartanbeno/go-reddit/v2/reddit"
)
const (
id = "createdappid"
secret = "createdappsecret"
username = "MarkkuIT"
password = "birthyear"
overviewUser = "MarkkuIT"
)
var api *reddit.Client
func init() {
var err error
credentials := reddit.Credentials{
ID: id,
Secret: secret,
Username: username,
Password: password,
}
api, err = reddit.NewClient(credentials)
if err != nil {
log.Fatalf("Error initializing Reddit API: %s\n", err.Error())
}
}
func main() {
if posts, comments, _, err := api.User.OverviewOf(context.Background(), overviewUser, nil); err == nil {
fmt.Printf("posts(%d) comments(%d)\n", len(posts), len(comments))
} else {
log.Fatal(err)
}
}
2021/05/13 12:32:58 Get "https://oauth.reddit.com/user/MarkkuIT/overview": oauth2: server response missing access_token
exit status 1
I doublechecked the credentials and they are indeed correct. What am I missing?
There is no support for submitting images using native api. Could you think about implement this behaviour?
Reddit API allows authorization for 3 app types:
At the moment it seems that go-reddit
only supports the latter use case -- oauthTransport
uses Username + Password to obtain and renew access tokens.
In order to send requests to Reddit's API on behalf of multiple users, we need to support OAuth2 for "web apps". (see also the API docs). Should be a rather simple change, as the standard oauth2
library also supports exchanging code for token.
I am using go-reddit
in one of my private projects and need this functionality, so I'll be happy to contribute a PR :)
I know of no easy way to find projects using other projects; it'd be neat to have a list -- even if not comprehensive -- of utilities using this library. Maybe you could open a wiki page and accept PRs against a project list?
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.