access_token error: missing param 'grant_type'

1,419 views
Skip to first unread message

Vinney K

unread,
Jun 29, 2012, 5:11:08 PM6/29/12
to disqu...@googlegroups.com
I am trying to implement OAuth 2.0 to enable the creation of threads via the Disqus API. However, I can't seem to get this working. I keep receiving a 400 response specifying
{"error_description": "Missing required parameter: grant_type", "error": "invalid_request"}.
 
 
Here is an example of the request:
 
POST /api/oauth/2.0/access_token/?client_id=...&client_secret=...&grant_type=authorization_code&redirect_url=...&code=... HTTP/1.1
 
Can anyone please help determine what I'm doing wrong? I've lost most of my day to trying to uncover the mysteries of this error. For what I can tell, I'm doing what the API doucmentation has explained.
 
Thanks,
Vinney

Marcor

unread,
Jul 2, 2012, 7:19:47 AM7/2/12
to disqu...@googlegroups.com
I've the same problem in C# (Windows 8) with this code:


HttpClient client = new HttpClient();


client.DefaultRequestHeaders.Authorization = System.Net.Http.Headers.AuthenticationHeaderValue.Parse("Basic ...");

HttpResponseMessage res = await client.PostAsync(str, null);

return await res.Content.ReadAsStringAsync();

Vinney K

unread,
Jul 2, 2012, 11:41:51 AM7/2/12
to disqu...@googlegroups.com
@Marcor,
 
According to this thread (https://groups.google.com/forum/?fromgroups#!topic/disqus-dev/S6SavcJzIck) you need to post the values via the request body rather than the querystring. That said, I've still not been able to get that working either; instead I get a new error about an invalid API version. I wont be back on that until tonight but I'll let you know if/when I figure it out. Hopefully you'll let me know if you beat me to the punch.
 
BTW, it's nice to see another .NET dev in this anti-.net world! Sexy async/await too!
 
Vinney
Message has been deleted

Marcor

unread,
Jul 3, 2012, 10:23:49 AM7/3/12
to disqu...@googlegroups.com
Thanks :)

this is the solution:

HttpClient client = new HttpClient();

client.DefaultRequestHeaders.Authorization = System.Net.Http.Headers.AuthenticationHeaderValue.Parse("Basic " + base64);

var postData = new List<KeyValuePair<string, string>>();
postData.Add(new KeyValuePair<string, string>("grant_type", "password"));
postData.Add(new KeyValuePair<string, string>("client_secret", App.SECRETKEY));
postData.Add(new KeyValuePair<string, string>("client_id", App.APIKEY));
postData.Add(new KeyValuePair<string, string>("scope", "read,write"));
HttpContent content = new FormUrlEncodedContent(postData);

HttpResponseMessage res = await client.PostAsync("https://disqus.com/api/oauth/2.0/access_token/", content);
Reply all
Reply to author
Forward
0 new messages