TwitterAPI

command module
v0.0.0-...-1ff5f12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 23, 2025 License: MIT Imports: 5 Imported by: 0

README

🐦 Twitter API SDK

A Modern, Feature-Rich Go SDK for Twitter API Automation

Stars Watchers Twitter API Go Version License

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.


Features

  • 🔐 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

Installation

go get github.com/0xStarLabs/TwitterAPI

Quick Start

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)
    }
}

Usage Examples

Following Users
// 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")
}
Posting Comments
// Simple comment
resp := twitter.Comment("Great tweet!", "1234567890", nil)

// Comment with media
resp = twitter.Comment("Check this out!", "1234567890", &client.CommentOptions{
    MediaBase64: imageBase64,
})
Getting User Info
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)
}

Advanced Configuration

Using Proxies
account := client.NewAccount(
    "auth_token_here",
    "csrf_token",  // optional
    "user:pass@host:port",  // proxy
)
Using JSON Cookies
authToken, csrfToken, err := client.SetAuthCookies(
    0,  // account index
    cookieClient,
    `[{"name":"auth_token","value":"token"}]`,
)

Error Handling

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)
    }
}

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Disclaimer

This project is not affiliated with Twitter. Use at your own risk and ensure compliance with Twitter's Terms of Service.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL