I received an email saying my use of the Twitter API v1.1 was being suspended. I went into my dev account and switched my app to the free tier to unsuspend it but now I'm having trouble posting tweets.
If I understand correctly, API v1.1 doesn't support posting tweets using the free tier. If I use API v2 to execute a POST, I receive a 401 Unauthorized. I've tried using both Oauth 1.0 and Oauth 2.0 with the same result. Sample code using an Oauth library is below.
OAuthRequest client = OAuthRequest.ForProtectedResource("POST", [ConsumerKey], [ConsumerSecret], [AccessToken], [AccessTokenSecret]);
client.RequestUrl = "https://api.twitter.com/2/tweets";
string auth = client.GetAuthorizationHeader();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(client.RequestUrl);
request.Method = "POST";
request.ContentType = "application/json";
request.Headers.Add("Authorization", auth);
using (var streamWriter = new StreamWriter(request.GetRequestStream()))
{
streamWriter.Write("{\"text\":\"Hello.\"");
}
var response = (HttpWebResponse)request.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();