Skip to main content
deleted 51 characters in body; edited tags
Source Link
Brock Adams
  • 13k
  • 5
  • 39
  • 64

I'm trying to connect to StackExchangeStack Exchange API using OAuth. So far i'veI've been able to get a token and retriveretrieve data that does not require authentication. When i try do query that uses the authentication, i'mI'm getting error 400 - Bad request. HeresHere'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.

I'm trying to connect to StackExchange API using OAuth. So far i've been able to get a token and retrive data that does not require authentication. When i try do query that uses the authentication, i'm getting error 400 - Bad request. Heres 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.

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.

Source Link
user27978
user27978

Getting Error 400 when using Authentication Broker in Win 8 App for Stackexchange API

I'm trying to connect to StackExchange API using OAuth. So far i've been able to get a token and retrive data that does not require authentication. When i try do query that uses the authentication, i'm getting error 400 - Bad request. Heres 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.