
Fast 🚀 Reliable 🛡️ Easy to Use 💡
A powerful Go SDK that provides seamless interaction with Twitter's API. Built with performance and ease of use in mind.
- 🔐 Account Management
- Account validation
- Support for auth tokens and JSON cookies
- Proxy support
- 👥 User Interactions
- Follow/Unfollow users
- Like/Retweet tweets
- Vote on polls
- Get user information
- Handle both usernames and user IDs
- 📝 Content Creation
- Post tweets
- Reply to tweets
- Add media to posts
- ⚡ Performance
- Efficient cookie management
- Automatic CSRF token handling
- Smart error handling
go get github.com/0xStarLabs/TwitterAPI
package main
import (
"fmt"
"github.com/0xStarLabs/TwitterAPI/client"
)
func main() {
// Create a new account
account := client.NewAccount("auth_token_here", "", "")
// Initialize Twitter client
twitter, err := client.NewTwitter(account)
if err != nil {
panic(err)
}
// Check if account is valid
info, resp := twitter.IsValid()
if resp.Success {
fmt.Printf("Account %s is valid\n", info.Username)
}
}
// Follow by username
resp := twitter.Follow("username")
if resp.Success {
fmt.Println("Successfully followed user")
}
// Unfollow by username or ID
resp = twitter.Unfollow("username")
if resp.Success {
fmt.Println("Successfully unfollowed user")
}
// Simple comment
resp := twitter.Comment("Great tweet!", "1234567890", nil)
// Comment with media
resp = twitter.Comment("Check this out!", "1234567890", &client.CommentOptions{
MediaBase64: imageBase64,
})
info, resp := twitter.GetUserInfoByUsername("username")
if resp.Success {
fmt.Printf("User ID: %s\n", info.Data.User.Result.RestID)
fmt.Printf("Followers: %d\n", info.Data.User.Result.Legacy.FollowersCount)
}
account := client.NewAccount(
"auth_token_here",
"csrf_token", // optional
"user:pass@host:port", // proxy
)
authToken, csrfToken, err := client.SetAuthCookies(
0, // account index
cookieClient,
`[{"name":"auth_token","value":"token"}]`,
)
The SDK uses a consistent error handling pattern:
resp := twitter.Follow("username")
if !resp.Success {
switch resp.Status {
case models.StatusAuthError:
fmt.Println("Authentication failed")
case models.StatusLocked:
fmt.Println("Account is locked")
default:
fmt.Printf("Error: %v\n", resp.Error)
}
}
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
This project is not affiliated with Twitter. Use at your own risk and ensure compliance with Twitter's Terms of Service.