1

I'm trying to connect to Stack Exchange API using OAuth. So far I've been able to get a token and retrieve data that does not require authentication. When i try do query that uses the authentication, I'm getting error 400 - Bad request. Here's the code:

Dim Key As String = "(app_key)"

Dim RequestURL As String = "https://api.stackexchange.com/2.2/me/questions?access_token=" & Token & "key=" & Key & "&order=desc&sort=activity&site=stackapps"

Dim Handler As HttpClientHandler = New HttpClientHandler()
If Handler.SupportsAutomaticDecompression Then 
       Handler.AutomaticDecompression = DecompressionMethods.GZip Or DecompressionMethods.Deflate
End If

Dim HttpClient As HttpClient = New HttpClient(Handler)

Dim query = Await HttpClient.GetAsync(RequestURL)

If query.IsSuccessStatusCode = True Then
     '(query.Content.ReadAsStringAsync())
End If

Tried using only key, only access token, or none in the request, but received the same error. Also tried adding "OAuth" header and "access_token":

HttpClient.DefaultRequestHeaders.Authorization = New AuthenticationHeaderValue("OAuth", Token)
HttpClient.DefaultRequestHeaders.Authorization = New AuthenticationHeaderValue("access_token", Token)

Any help appreciated.

2
  • "key=" should be "&key=". Commented Aug 6, 2014 at 0:13
  • Yes. I fixed, but i'm having the same error.
    – user27978
    Commented Aug 8, 2014 at 18:47

1 Answer 1

0

Solved it! Turns out a was using the wrong key. I managed to make it work by using both access_token and key in the RequestUrl, and not using the request headers.

You must log in to answer this question.