Take the 2-minute tour ×
Stack Apps is a question and answer site for apps, scripts, and development with the Stack Exchange API. It's 100% free, no registration required.

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
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.

share|improve this question
"key=" should be "&key=". –  Brock Adams Aug 6 at 0:13
Yes. I fixed, but i'm having the same error. –  Daniel Marques Aug 8 at 18:47

1 Answer 1

up vote 0 down vote accepted

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.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .