0

I am trying to do this curl call to the new yahoo weather api with OAuth 1 like so:

[HttpGet]
public HttpResponseMessage getWeather()
{

    using (HttpClient httpClient = new HttpClient())
    {

        httpClient.BaseAddress = new Uri("http://weather-ydn-yql.media.yahoo.com/");

        httpClient.DefaultRequestHeaders.Accept.Clear();

        httpClient.DefaultRequestHeaders.Add("Authorization", "OAuth oauth_consumer_key = \"(MY CONSUMER KEY)\", oauth_signature_method = \"HMAC-SHA1\", oauth_timestamp = \"1547473450\", oauth_nonce = \"Ll7ArdU1yN0\", oauth_version = \"1.0\", oauth_signature = \"(MY GENERATED SIGNATURE FROM POSTMAN)\"");

        //httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("OAuth", "oauth_consumer_key = \"(MY CONSUMER KEY)\", oauth_signature_method = \"HMAC-SHA1\", oauth_timestamp = \"1547472939\", oauth_nonce = \"vu3HE92s6A3\", oauth_version = \"1.0\", oauth_signature = \"(MY GENERATED SIGNATURE FROM POSTMAN)\"");

        HttpResponseMessage response = httpClient.GetAsync("forecastrss?location=hamilton&format=json").Result;

        return response;
    }
}

But when I run this it returns this error:

Please provide valid credentials. OAuth oauth_problem="OST_OAUTH_PARAMETER_ABSENT_ERROR", realm="yahooapis.com"

So it appears that my OAuth parameters are missing. My Question is how do I do a curl in ASP.NET C# with OAuth 1 authentication?

1 Answer 1

1

Figured it out using RestClient

var client = new RestClient("http://weather-ydn-yql.media.yahoo.com/forecastrss?location=hamilton&format=xml");
var request = new RestRequest(Method.GET);
request.AddHeader("Postman-Token", "ac0c256b-e727-4b01-b4fe-edd8b7d7073a");
request.AddHeader("cache-control", "no-cache");
request.AddHeader("Authorization", "OAuth oauth_consumer_key="(MY CONSUMER KEY)",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1547481203",oauth_nonce="304ixaov43G",oauth_version="1.0",oauth_signature="(MY GENERATED SIGNATURE FROM POSTMAN)"");
IRestResponse response = client.Execute(request);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.