2

I'm trying to connect to the StackExchange API in R.

When I try:

library(httr)
end <- oauth_endpoint(authorize   = "https://stackoverflow.com/oauth",
                           access = "https://stackoverflow.com/oauth")

myapp <- oauth_app("myapp",
                   key    = "KEY",           # tried swapping these
                   secret = "CLIENT SECRET",
                   redirect_uri = "https://stackoverflow.com/oauth/login_success")

token <- oauth2.0_token(end,
                        myapp)

The browser opens but leads to the following message (in the browser):

Couldn't parse `client_id`

This also happens if I try it with opposite (reversed) values of key and secret, or event with key set to either value and secret=NULL (just to test without privileged access).

The StackExchange API docs say that the key value they give you is not really a secret but the client_secret value is. In the oauth_app help it says that the secret "is not equivalent to a password, and is not really a secret". Interesting.

For now I'm just trying to establish an initial test connection.

Update: I was curious if it was actually a matter of not being able to parse special character. I tried escaping the 2 parentheses ((() in my key and client_secret. That didn't change anything. I then tried setting both to an empty string (i.e. key = "", etc) and yet that somehow led to the same result. I feel it's a clue but I still don't know what's wrong.

Hack-R
  • 22,422
  • 14
  • 75
  • 131

2 Answers2

2

You're using implicit ("Client side") OAuth(SE API Doc).

That means that the auth sequence should look like this example:

  1. Your app HTTP GETS:

    https://stackexchange.com/oauth/dialog?client_id=4709&scope=private_info&redirect_uri=https://stackexchange.com/oauth/login_success
    

    Where client_idand scope are set to your circumstances.

  2. Your app is then redirected to:

    https://stackexchange.com/oauth/login_success#access_token=wdR8Lm7m4ibD48lfrCcFxQ))&expires=86399
    

    For example.

    Where access_token is what you need for subsequent calls that require authentication.

I'm no r coder, but guess that the syntax should be something like:

myapp <- oauth_app("myapp",
    client_id   = "{Your App's ID}",
    scope       = "private_info",  #  Or whatever is desired. See the doc page linked above
    redirect_uri = "https://stackoverflow.com/oauth/login_success")
  • client_secret is only used for server-side (explicit) OAuth.
  • pass key in all subsequent calls, OAuth needed or not, for quota purposes.
Brock Adams
  • 90,639
  • 22
  • 233
  • 295
0

I was getting the same error, my issue was that I was using the client secret as a value for my client_id parameter

Amar Dev
  • 1,360
  • 2
  • 18
  • 38