Giter Site home page Giter Site logo

go-reddit's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

go-reddit's Issues

markdown image sizing?

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!

Push release

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.

OAuth: server response missing access token

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
click me to see the request that is sent
{
   "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.

badger badger Blocked because of go-reddit and golang changes

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!

media of reddit post

Hi,

Can you add a field in Post that contains all media present in reddit Post (reddit returns a field called "media_metadata")

thanks

Unable to download: package github.com/vartanbeno/go-reddit: no Go files in /home/<username>/go/src/github.com/vartanbeno/go-reddit

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.

Response doesn't have api call body if reddit reports no rate limit left, even if api call was successful

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.

Authenticate with scopes

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.

searchpost params error

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.

How do I get the header image for a post?

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

Error Type Vagueness

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.

undefined: `reddit.DefaultClient` and `reddit.NewDefaultClient`

For some reason I can't access these? Weird, cause reddit.NewClient works

Steps to Reproduce

Set up Project

$ 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()
}

Run Project, See Error

$ go run main.go
# command-line-arguments
./main.go:6:9: undefined: reddit.NewReadonlyClient

Go Version

$ go version
go version go1.15.1 darwin/amd64

upvoting a post shows error 400

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
}

403 Forbidden

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)
        
        }

401 Unauthorized

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.

Authentication error ("oauth2: server response missing access_token")

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?

[Feature request]: Authorization flow for "web app"

Reddit API allows authorization for 3 app types:

  • web app
  • installed app
  • script

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 :)

REQUEST: Add a "projects using go-reddit" section

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.