briandowns/openweathermap

Requests still return invalid API key with code 401

DarkFighterLuke opened this issue · 2 comments

When trying to get forecast for 5 days, I always get invalid API key, even if more than 2 hours are passed from the creation of the account+API key.

Here is the code:

package main

import(
    "log"
    owm "github.com/briandowns/openweathermap"
    "fmt"
)

var apiKey="DEFAULT KEY PROVIDED BY OPENWEATHER"

func main() {

    
    w, err := owm.NewForecast("5", "C", "IT", apiKey) // valid options for first parameter are "5" and "16"
    if err != nil {
        log.Fatalln(err)
    }
    
    //w.DailyByName("Locorotondo", 7)
    w.DailyByCoordinates(&owm.Coordinates{Longitude: -112.07,Latitude: 33.45,}, 5)
	fmt.Println(w)
}

I think that the problem is in the URL parsing, because in the error i get
&{metric IT DEFAULT_API_KEY http://api.openweathermap.org/data/2.5/forecast?appid=%s&%s&mode=json&units=%s&lang=%s&cnt=%d 0xc0000b0018 0xc0000ee000}

While when I try from the web browser the key works.

Took a look at the code, understood how it works and that the URL was just the baseURL and not yet filled with fields data, documentation should be improved with examples of how to handle data got by the API.