vartanbeno / go-reddit

Go library for accessing the Reddit API.
Other
304 stars 81 forks source link

OAuth: server response missing access token #31

Open samox73 opened 2 years ago

samox73 commented 2 years ago

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.

samox73 commented 2 years ago

@vartanbeno has this project been abandoned? I am also getting the

<p>reddit's awesome and all, but you may have a bit of a
problem. we've seen far too many requests come from your ip address
recently.</p>

error when running the examples, no matter which machine I run it from.

caner-cetin commented 2 years ago

Also getting OAuth error and this issue is from April. Code is long abandoned.

dutchdata commented 2 years ago

I just got to this page. I have been using graw and its subpackage, graw/reddit (https://github.com/turnage/graw & https://github.com/turnage/graw/reddit). The repo seems to be maintained actively and by many contributors.

I noticed a couple major differences between this repo and the aforementioned ones:

  1. The config does not require a user-agent -- does it automatically create one?
  2. So far, I have not read anything about this package regarding "waiting between requests" -- graw/reddit waits 1 second between requests to avoid hitting Reddit's 60-requests-per-minute limit.

To all above, I have gotten the same error only when exceeding Reddit's API limits. I am wondering if this package puts the onus on the user to time requests appropriately.

Hope this helps. And, if I have overlooked something in this repo's docs regarding the above assertions, please let me know.

Additionally, I only came to this repo because I am having trouble setting up event streams with graw and graw/reddit. Has anyone else had this issue?

jgibat commented 1 year ago

Hi, got the same issue so I dug into this a bit. You can see in reddit-oauth.go that it uses password auth, so I tested grant_type=password manually w/curl and got the following error:

{"error_description": "Only script apps may use password auth", "error": "unauthorized_client"}

I created a new app of type 'script' and can successfully authenticate and use go-reddit now. hope this helps.

dutchdata commented 1 year ago

Good find! Thank you for posting this. Also glad it wasn't just me.

On Sun, Jan 22, 2023 at 08:53 jgibat @.***> wrote:

Hi, got the same issue so I dug into this a bit. You can see in reddit-oauth.go that it uses password auth, so I tested grant_type=password manually w/curl and got the following error:

{"error_description": "Only script apps may use password auth", "error": "unauthorized_client"}

I created a new app of type 'script' and can successfully authenticate and use go-reddit now. hope this helps.

— Reply to this email directly, view it on GitHub https://github.com/vartanbeno/go-reddit/issues/31#issuecomment-1399527975, or unsubscribe https://github.com/notifications/unsubscribe-auth/AUWVMO6NDQQO7TRNEHXVM5DWTVJZFANCNFSM5QVOHPYA . You are receiving this because you commented.Message ID: @.***>

ashaller2017 commented 1 year ago

to anyone here I think most likely you guys are using a webapp or mobile app for the reddit api.. request a script app and it helps ease the oauth problem without having to go pull down the git and fix the reddit-auth file