3

I'm trying to access the HackerNews API to practice Go.

Anytime I go to my localhost to try see an output from Firebase database (where the data is stored) I am met with a Google Accounts authentication form.

Any help on this would be appreciated. In my terminal I used curl to check if I was getting a response from the server. I got a 200 OK response with content.

I thought I might be missing a Firebase client library but I'm not sure if that is the issue right now.

package main

import (
    "fmt"
    "io/ioutil"
    "log"
    "net/http"
)

func handler(w http.ResponseWriter, r *http.Request) {
    response, err := http.Get("https://hacker-news.firebaseio.com/v0/item/8863.json")
    if err != nil {
        fmt.Printf("The http request failed with the error %s\n", err)
    } else {
        data, _ := ioutil.ReadAll(response.Body)
        fmt.Fprintf(w, string(data))
    }
}
func main() {
    fmt.Println("Starting the applicaiton")
    http.HandleFunc("/", handler)
    log.Fatal(http.ListenAndServe(":8080", nil))

}
Zoe
  • 27,060
  • 21
  • 118
  • 148
mangokitty
  • 1,759
  • 3
  • 12
  • 17
  • It appears like the API you call requires authentication, and it is probably using oauth, so it is redirecting you to authenticate. If you have a token for this API, add that to the header so it can authenticate you. – Burak Serdar Jan 14 '20 at 17:29

1 Answers1

3

Aren't you suppose to add .json to URL (via https://github.com/HackerNews/API)?

e.g https://hacker-news.firebaseio.com/v0/item/8863.json

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Oleg Butuzov
  • 4,795
  • 2
  • 24
  • 33