TikTok API for Go.
Clean example request for the media downloader endpoint. Replace YOUR API and the media URL, then run the code.
Checking
Clean example request for the media downloader endpoint. Replace YOUR API and the media URL, then run the code.
package main
import (
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"net/url"
)
const (
apiKey = "YOUR API"
videoURL = "URL TIKTOK"
endpoint = "https://senpai-bot.store/tiktokdl"
)
type UsernameInfo struct {
Avatar string `json:"avatar"`
ID string `json:"id"`
Nickname string `json:"nickname"`
UniqueID string `json:"unique_id"`
}
type Result struct {
AudioURL string `json:"audio_url"`
CommentCount int `json:"comment_count"`
CoverTrack string `json:"cover_track"`
Created int64 `json:"created"`
DownloadCount int `json:"download_count"`
Duration int `json:"duration"`
Fullname interface{} `json:"fullname"`
LikeCount int `json:"like_count"`
Music string `json:"music"`
NoWatermarkURL string `json:"no_watermark_url"`
PictureURL interface{} `json:"picture_url"`
PlayCount int `json:"play_count"`
ShareCount int `json:"share_count"`
ThumbnailURL string `json:"thumbnail_url"`
Title string `json:"title"`
TitleCount int `json:"title_count"`
Username UsernameInfo `json:"username"`
VideoPicture string `json:"video_picture"`
WatermarkURL string `json:"watermark_url"`
}
type ApiResponse struct {
Code int `json:"code"`
Result Result `json:"result"`
}
func main() {
encodedVideoURL := url.QueryEscape(videoURL)
getData := fmt.Sprintf("%s?apikey=%s&url=%s", endpoint, apiKey, encodedVideoURL)
resp, err := http.Get(getData)
if err != nil {
log.Fatalf("Error making request: %v", err)
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatalf("Error reading response: %v", err)
}
var response ApiResponse
if err := json.Unmarshal(body, &response); err != nil {
log.Fatalf("Error parsing JSON: %v", err)
}
r := response.Result
fmt.Println("Username:", r.Username.UniqueID)
fmt.Println("Nickname:", r.Username.Nickname)
fmt.Println("Avatar:", r.Username.Avatar)
fmt.Println("Title:", r.Title)
fmt.Println("Title Count:", r.TitleCount)
fmt.Println("Duration:", r.Duration)
fmt.Println("Like Count:", r.LikeCount)
fmt.Println("Comment Count:", r.CommentCount)
fmt.Println("Share Count:", r.ShareCount)
fmt.Println("Play Count:", r.PlayCount)
fmt.Println("Download Count:", r.DownloadCount)
fmt.Println("Created:", r.Created)
fmt.Println("Cover Track:", r.CoverTrack)
fmt.Println("Audio URL:", r.AudioURL)
fmt.Println("Video Picture:", r.VideoPicture)
fmt.Println("Thumbnail URL:", r.ThumbnailURL)
fmt.Println("Watermark URL:", r.WatermarkURL)
fmt.Println("No Watermark URL:", r.NoWatermarkURL)
}