I was trying out the application-only auth and was going through the steps here: https://dev.twitter.com/docs/auth/application-only-auth. On step 2 I got a response with “StatusCode 200 OK” and I saw a bunch of headers but there wasn’t anything that said “token_type” or “access_token”. I’m really new to making web requests and asynchronous operations with desktop applications so I might be doing something obviously wrong.
Here’s a snippet of my desktop application in C# using .NET
public static string Request_BearerToken(string encoded_credentials)
{
using (var client = new HttpClient())
{
string content_type = "application/x-www-form-urlencoded;charset=utf8";
string user_agent = "GenghisDesktopApp";
client.DefaultRequestHeaders.Accept.Add(MediaTypeWithQualityHeaderValue.Parse(content_type));
client.DefaultRequestHeaders.Add("Authorization", String.Format("Basic {0}", encoded_credentials));
client.DefaultRequestHeaders.Add("User-Agent",user_agent);
client.DefaultRequestHeaders.Add("Content_Length", "29");
client.DefaultRequestHeaders.Add("Accept-Encoding", "gzip");
client.DefaultRequestHeaders.Add("Host", "api.twitter.com");
HttpContent body = new StringContent("grant_type=client_credentials");
body.Headers.ContentType = MediaTypeHeaderValue.Parse(content_type);
HttpResponseMessage response = client.PostAsync("https://api.twitter.com/oauth2/token", body).Result;
Console.WriteLine(response);
Console.Read();
}
return "bearer token should go here";
}