【问题标题】:Accessing HackerNews API访问 HackerNews API
【发布时间】:2020-01-14 17:23:11
【问题描述】:

我正在尝试访问 HackerNews API 来练习围棋。

每当我去我的本地主机尝试查看 Firebase 数据库(存储数据的地方)的输出时,我都会遇到一个 Google 帐户身份验证表单。

对此的任何帮助将不胜感激。在我的终端中,我使用 curl 检查是否收到了来自服务器的响应。我收到了 200 OK 的内容响应。

我以为我可能缺少 Firebase 客户端库,但我不确定这是否是现在的问题。

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))

}

【问题讨论】:

  • 您调用的 API 似乎需要身份验证,并且可能正在使用 oauth,因此它正在重定向您进行身份验证。如果您有此 API 的令牌,请将其添加到标头中,以便它可以对您进行身份验证。

标签: firebase go hacker-news-api


【解决方案1】:

您不打算将.json 添加到URL(通过https://github.com/HackerNews/API)吗?

例如https://hacker-news.firebaseio.com/v0/item/8863.json

【讨论】:

  • 是的,抱歉,我尝试了不同的端点,却忘了放回去。它应该 100% 存在。
猜你喜欢
  • 2021-05-24
  • 1970-01-01
  • 2023-01-09
  • 1970-01-01
  • 2018-08-01
  • 2017-07-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多