This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
e621-sdk-go/example/lowlevel/favorite.go
SoXX d9fb7dfb88 feat: added favorites
Signed-off-by: SoXX <soxx@fenpa.ws>
2023-10-19 16:12:56 +02:00

61 lines
1.5 KiB
Go

package main
import (
"git.dragse.it/anthrove/e621-to-graph/pkg/e621/endpoints"
"git.dragse.it/anthrove/e621-to-graph/pkg/e621/model"
"log"
"net/http"
)
func main() {
// Define the request context with essential information.
requestContext := model.RequestContext{
Host: "https://e621.net",
UserAgent: "Go-e621-SDK (@username)",
Username: "", // Replace with your username
APIKey: "", // Replace with your API key
}
// Log: Getting favorites from the API.
log.Println("Getting favorites API user: ")
// Initialize an HTTP client.
client := http.Client{}
// Define query parameters for retrieving favorites.
query := map[string]string{
"limit": "5",
}
// Call the GetFavorites function to retrieve favorite posts.
posts, err := endpoints.GetFavorites(client, requestContext, query)
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: ")
// Update the query parameters to include a specific user's ID.
query = map[string]string{
"user_id": "25483", // Replace with the desired user's ID
"limit": "5",
}
// Call the GetFavorites function to retrieve favorite posts for the specified user.
posts, err = endpoints.GetFavorites(client, requestContext, query)
if err != nil {
log.Println(err)
} else {
// Log the URL of the first favorite post.
log.Println(posts[0].File.URL)
}
log.Println("----------")
}