Stack Apps is a question and answer site for apps, scripts, and development with the Stack Exchange API. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 = "" & 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 '14 at 0:13
Yes. I fixed, but i'm having the same error. – Daniel Marques Aug 8 '14 at 18:47
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 .