Printear lo que nos da OpenSea, setear User-Agent a uno común y bajar limite para que funcione API

This commit is contained in:
Cat /dev/Nulo 2022-01-28 16:51:02 -03:00
parent 0c4e1fc904
commit 1d2ea468b6

View file

@ -2,6 +2,8 @@ package main
import (
"encoding/json"
"io/ioutil"
"log"
"math"
"net/http"
"strconv"
@ -57,15 +59,25 @@ func GetAssets() (Assets, error) {
} `json:"assets"`
}{}
assets := Assets{}
res, err := http.DefaultClient.Get("https://api.opensea.io/api/v1/assets" +
"?order_direction=desc" +
"&offset=0" +
"&limit=50" +
"&order_by=sale_date")
req, err := http.NewRequest("GET", "https://api.opensea.io/api/v1/assets"+
"?order_direction=desc"+
"&offset=0"+
"&limit=20"+
"&order_by=sale_date", nil)
if err != nil {
return assets, err
}
err = json.NewDecoder(res.Body).Decode(&parsed)
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36")
res, err := http.DefaultClient.Do(req)
if err != nil {
return assets, err
}
bytes, err := ioutil.ReadAll(res.Body)
log.Println(string(bytes))
if err != nil {
return assets, err
}
err = json.Unmarshal(bytes, &parsed)
if err != nil {
return assets, err
}