Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The 'Accept' header must be modified using the appropriate property or method - TwitchAPI

My problem, as you can see in the title, is I get an exception when adding the header. What I'm trying to do is send an authorization request to the public TwitchAPI. Here's the request that I'm trying to translate:

curl -H 'Accept: application/vnd.twitchtv.v3+json' 
-H 'Authorization: OAuth <access_token>' \ 
-X GET https://api.twitch.tv/kraken/channel

It's when I add the Accept header where this exception pops up in my face (title). I'm not sure if I've translated this correctly but this is the code I have right now:

Dim wr = CType(WebRequest.Create("https://api.twitch.tv/kraken/channel"), HttpWebRequest)
wr.Method = "GET"
wr.Headers.Add("Authorization: OAuth <oauth_token>")
wr.Headers.Add("Accept: application/vnd.twitchtv.v3+json")
Return CType(wr.GetResponse(), HttpWebResponse)

where oauth_token is my access token, anyone who could solve this for me? Really worked my ass off trying to figure out such a simple thing, thanks!

  • Oh and also, when I remove the header (which I actually think is unnecessary) it says im unauthorized, using the correct access token.
like image 730
ElementalTree Avatar asked Apr 08 '15 12:04

ElementalTree


1 Answers

The HttpWebRequest class has a specific Accept property for setting the 'Accept' header

Dim wr = CType(WebRequest.Create("https://api.twitch.tv/kraken/channel"), HttpWebRequest)
wr.Method = "GET"
wr.Headers.Add("Authorization: OAuth <oauth_token>")
wr.Accept = "application/vnd.twitchtv.v3+json"
Return CType(wr.GetResponse(), HttpWebResponse)
like image 195
John O. Avatar answered Oct 15 '22 21:10

John O.