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

OAuth: server response missing access token #31

Open
samox73 opened this issue Mar 14, 2022 · 6 comments
Open

OAuth: server response missing access token #31

samox73 opened this issue Mar 14, 2022 · 6 comments

Comments

@samox73
Copy link

samox73 commented Mar 14, 2022

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
Copy link
Author

samox73 commented Apr 2, 2022

@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
Copy link

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

@dutchdata
Copy link

dutchdata commented Jul 8, 2022

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
Copy link

jgibat commented Jan 22, 2023

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
Copy link

dutchdata commented Jan 22, 2023 via email

@ashaller2017
Copy link

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

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

No branches or pull requests

5 participants