goodniko
goodniko

Reputation: 163

OAuth. Twitter. StatusCode: 403. SSL is required. C#

I need your help!

My code:

 string twitterRequestTokenUrl = "http://api.twitter.com/oauth/request_token";


HttpRequestMessage request = new HttpRequestMessage();
    string data = "oauth_consumer_key=\"" + oauth_consumer_key +
                   "\", oauth_nonce=\"" + oauth_nonce +
                   "\", oauth_signature=\"" + Uri.EscapeDataString(oauth_signature) +
                   "\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"" + oauth_timestamp +
                   "\", oauth_version=\"1.0\"";
    request.Headers.Authorization = new       System.Net.Http.Headers.AuthenticationHeaderValue("OAuth", data);
    request.RequestUri = new Uri(twitterRequestTokenUrl, UriKind.Absolute);

    request.Method = new HttpMethod("POST");    
    var response = await httpClient.SendAsync(request);

What could be the problem, I send an inquiry:

request {Method: POST, RequestUri: 'http://api.twitter.com/oauth/request_token', Version: 1.1, Content: , Headers: { Authorization: OAuth oauth_consumer_key="*******************", oauth_nonce="NjM1NjQwOTY0MzAzMjMwNjgw", oauth_signature="nIQIuJqRLP2naUxgC0cTHqFqUkc%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1428485230", oauth_version="1.0" }} System.Net.Http.HttpRequestMessage

and get the following answer:

StatusCode: 403, ReasonPhrase: 'Forbidden', Version: 1.1, Content: System.Net.Http.StreamContent, Headers: { connection: close date: Wed, 08 Apr 2015 09:06:50 GMT server: tsa_b set-cookie: guest_id=v1%3A142848401049508299; Domain=.twitter.com; Path=/; Expires=Fri, 07-Apr-2017 09:06:50 UTC x-connection-hash: 407806cc38f466361aa7e9efb2a35601 x-response-time: 5 Content-Length: 16 content-type: text/plain; charset=utf-8 } SSL is required

Upvotes: 0

Views: 1344

Answers (1)

Awad Maharoof
Awad Maharoof

Reputation: 2370

changing

string twitterRequestTokenUrl = "http://api.twitter.com/oauth/request_token";

to

string twitterRequestTokenUrl = "https://api.twitter.com/oauth/request_token";

should solve your issue.

The reason you are seeing a status code of 403 is since "only SSL connections are allowed in Twitter API endpoints"

Upvotes: 0

Related Questions