Twitter 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_KEY"
tweetURL = "URL TWITTER"
endpoint = "https://senpai-bot.store/twitterdl"
)
type TwitterResult struct {
Title string `json:"title"`
Thumbnail string `json:"thumbnail"`
Duration interface{} `json:"duration"`
VideoURL string `json:"video_url"`
Quality string `json:"quality"`
Username string `json:"username"`
UploadDate string `json:"upload_date"`
ViewCount interface{} `json:"view_count"`
}
type ApiResponse struct {
Code int `json:"code"`
Result TwitterResult `json:"result"`
}
func main() {
encodedTweetURL := url.QueryEscape(tweetURL)
fullURL := fmt.Sprintf("%s?apikey=%s&url=%s", endpoint, apiKey, encodedTweetURL)
resp, err := http.Get(fullURL)
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)
}
if response.Code != 200 {
log.Fatalf("API returned error code: %d", response.Code)
}
r := response.Result
fmt.Println("Title :", r.Title)
fmt.Println("Username :", r.Username)
fmt.Println("Upload Date :", r.UploadDate)
fmt.Println("Quality :", r.Quality)
fmt.Println("Video URL :", r.VideoURL)
if r.Thumbnail != "" {
fmt.Println("Thumbnail :", r.Thumbnail)
} else {
fmt.Println("Thumbnail : (null)")
}
if r.Duration != nil {
fmt.Println("Duration :", r.Duration)
} else {
fmt.Println("Duration : (null)")
}
if r.ViewCount != nil {
fmt.Println("Views :", r.ViewCount)
} else {
fmt.Println("Views : (null)")
}
}