Using your Open Weather Map API key

If you are reading this, you are probably trying to figure out how to use your api key from openweathermap.org. If you are reading this and don’t know what that is, don’t feel bad. I didn’t either until I started my Android Developer Course. In a nutshell, when your phone app tells you the weather, it gets it from a server somewhere in a special format, called an API, which returns a JSON object. At least, that’s how I understand it.

The problem is, that server will not just tell anyone the data. All of these servers want you to have a key. Most sites offer some sort of free plan for a very limited number of calls, particularly for developers or for personal use. This requires an account. So I got one at openweathermap, and then was given a key.

One of the principle things you need to get the api data from a provider is an api key. This is where I was having big trouble. After registering and getting the key, I then went to the guide on how to use it. It is located here if you are interested, but it didn’t work.

http://openweathermap.org/appid#get

In the guide it told me to use this call method:

http://api.openweathermap.org/data/2.5/forecast/city?id=524901&APPID=1111111111

Except with my key after APPID=, instead of the 111111111’s. The problem was, it would return this error when I made the call:

{“cod”:401, “message”: “Invalid API key. Please see http://openweathermap.org/faq#error401 for more info.”}

or sometimes this one:

“This site can’t be reached

api.openweathermap.org refused to connect.”

I was getting a little bit frustrated. I reread the documentation, and I still got bad results. I waited until the next day to make sure my calls per day were reset. Still no luck. I googled, I searched, and eventually, I got to this thread:

https://github.com/cmfcmf/OpenWeatherMap-PHP-Api/issues/46

Where I learned two really important things that made it all work:

#1. Don’t use https:// in the call, use http:// instead.

#2. Instead of APPID in the call, use appid (lowercase) in the call to get the results.

Once I did these two things, it immediately started working for me. So if you are having trouble, you should give that a try. Hopefully this will save you hours of frustration.

Linux – keep it simple.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s