0

I am a newbie coldfusion developer. And I want to get yahoo weather information using coldfusion.

So I made a cfm file like this.

<cfset theURL = "https://weather-ydn-yql.media.yahoo.com/forecastrss?location=sunnyvale,ca">
<cfhttp url="#theURL#" charset="utf-8" method="post">
    <cfhttpparam type="formfield" name="appid" value="2a0Lkq6k">
    <cfhttpparam type="formfield" name="context" value="dj0yJmk9MkxEcTlzVDNucE5hJnM9Y29uc3VtZXJzZWNyZXQmc3Y9MCZ4PWMx">
    <cfhttpparam type="formfield" name="query" value="madonna">
</cfhttp>

And I got a error like this.

Your call to Yahoo Web Services returned an unexpected HTTP status of: 401

I have rich experience in laravel, django or so. But I don't know coldfusion as well as yahoo weather api.

How can I fix this and get the result?

Alex
  • 7,743
  • 1
  • 18
  • 38
VanHau
  • 111
  • 1
  • 1
  • 5
  • There seems to be something missing between your first two paragraphs. – Dan Bracuk Jan 19 '19 at 17:19
  • Do you know how to edit your question to add this information? – Dan Bracuk Jan 19 '19 at 18:28
  • Are you sure this is the correct endpoint? We are using `https://query.yahooapis.com/v1/public/yql` to query weather information. You also mixing GET and POST parameter. Can you link us the docs you are using? – Alex Jan 19 '19 at 20:18
  • 2
    If you have experience with PHP/Laravel than this should be easy for you as well. `cfhttp` is very similar to PHP's `curl`. 401 means you are unauthorized and it looks like it wants oAuth authentication `OAuth oauth_problem="OST_OAUTH_PARAMETER_ABSENT_ERROR", realm="yahooapis.com` – Cory Fail Jan 19 '19 at 21:06
  • 1
    you can visit here https://developer.yahoo.com/weather/ and at the top of the page it says use https://weather-ydn-yql.media.yahoo.com/forecastrss. – VanHau Jan 20 '19 at 15:12
  • thanks fyroc. it means that to use yahoo weather api, I need oAuth authentication. right? But I don't know how to do it. If you are a pro coldfusion developer, can you please tell me how to do it? – VanHau Jan 20 '19 at 15:13
  • 2
    After using Yahoo for many years, I moved to Dark Sky (1,000 calls per day for free, no oAuth required) and have been very happy https://darksky.net/dev Check it out. – James Moberg Jan 20 '19 at 17:07
  • 1
    It also says **"Follow below instructions to get credentials and onboard to this free Yahoo Weather API service."** Did you do that yet? – SOS Jan 20 '19 at 18:48
  • Yeah, so I have AppID, ClientID and SecretID but I don't know how to use it. Can you help me with it? – VanHau Jan 21 '19 at 10:55
  • I don't know the api. If it were me, rather than waiting for someone to give me the code, I'd read the instructions - which seem straightforward - try some oauth code and post back if those new attempts didn't work. It doesn't look like you've attempted that yet. – SOS Jan 21 '19 at 17:10
  • Actually, I tried and got an OAuth2 error. like this. Error: redirect_uri_mismatch – VanHau Jan 22 '19 at 18:29
  • 1
    https://stackoverflow.com/questions/11485271/google-oauth-2-authorization-error-redirect-uri-mismatch – Shawn Jan 22 '19 at 20:01
  • And have you gone through these steps? https://developer.yahoo.com/weather/ – Shawn Jan 22 '19 at 20:01
  • And, as James Moberg said, there's always Dark Sky. – Shawn Jan 22 '19 at 20:01
  • For future reference, to make the best use of everyone's time - and get faster anwers - all of those things should've been included in the *original question* ;-) – SOS Jan 22 '19 at 20:46
  • Just an FYI: after spending a few minutes looking at it, it looks like it will require a lot of processing just to build up the values required in the OAuth header string. Once that's done, it's a fairly small call through `cfhttp`, but it is _BY FAR_ easier to use the Dark Sky API. And it's weather, so it should be about the same info. The hardest thing would be to find the Latitude and Longitude of the location you're querying. But if you have that, it's as simple as ``. – Shawn Jan 22 '19 at 21:44
  • https://darksky.net/dev/docs – Shawn Jan 22 '19 at 21:44

0 Answers0