e621-sdk-go/example/midlevel/favorite.go
Alphyron 214aaceee0
All checks were successful
Gitea Build Check / Build (pull_request) Successful in 35s
chore: update mod path and update dependencies
2024-08-20 08:07:46 +02:00

50 lines
1.3 KiB
Go

package main
import (
"git.anthrove.art/Anthrove/e621-sdk-go/pkg/e621/builder"
"git.anthrove.art/Anthrove/e621-sdk-go/pkg/e621/model"
_ "github.com/joho/godotenv/autoload"
"log"
"net/http"
"os"
)
func main() {
// Define the request context with essential information.
requestContext := model.RequestContext{
Client: http.Client{},
Host: "https://e621.net",
UserAgent: "Go-e621-SDK (@username)",
Username: os.Getenv("API_USER"), // Replace with your username
APIKey: os.Getenv("API_KEY"), // Replace with your API key
}
// Log: Getting favorites from the API.
log.Println("Getting favorites API user: ")
// Call the GetFavorites function to retrieve favorite posts.
getFavorites := builder.NewGetFavoritesBuilder(requestContext)
posts, err := getFavorites.SetLimit(5).Execute()
if err != nil {
log.Println(err)
} else {
// Log the URL of the first favorite post.
log.Println(posts[0].File.URL)
}
log.Println("----------")
// Log: Getting favorites for a specific user.
log.Println("Getting favorites for user: ")
// Call the GetFavorites function to retrieve favorite posts for the specified user.
posts, err = getFavorites.SetLimit(5).SetUserID(1337).Execute()
if err != nil {
log.Println(err)
} else {
// Log the URL of the first favorite post.
log.Println(posts[0].File.URL)
}
log.Println("----------")
}