twitter

package
v0.0.0-...-81bdd1b Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultBaseURL = "https://api.twitter.com/2"

DefaultBaseURL used for API requests. Use WithBaseURL() to change.

View Source
const DefaultTweetFields = "id,author_id,created_at,text"

DefaultTweetFields is the default list of tweet fields requested.

View Source
const DefaultUserFields = "id,name,username,created_at,description,location,pinned_tweet_id,profile_image_url,protected,url,verified,withheld"

DefaultUserFields is the default list of user fields requested.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a Twitter API client.

func NewClient

func NewClient(httpClient HTTPClient, options ...ClientOption) *Client

NewClient returns a new Client struct.

func (*Client) Block

func (c *Client) Block(user string, targetUser string) (bool, error)

Block causes the user to block the target user. API: https://developer.twitter.com/en/docs/twitter-api/users/blocks/api-reference/post-users-user_id-blocking Rate limit: 50 requests per 15-minute window per each authenticated user.

func (*Client) DoRequest

func (c *Client) DoRequest(req *http.Request, v interface{}) error

DoRequest makes a request to the API and unmarshales the response into v.

func (*Client) LikingUsers

func (c *Client) LikingUsers(id string, params *url.Values) *LikingUsersInterator

LikingUsers returns an iterator to get information about a Tweet’s liking users. API: https://developer.twitter.com/en/docs/twitter-api/tweets/likes/api-reference/get-tweets-id-liking_users Rate limit: 75 requests per 15-minute window per each authenticated user.

func (*Client) Me

func (c *Client) Me(params *url.Values) (*User, error)

Me returns information about an authorized user. API: https://developer.twitter.com/en/docs/twitter-api/users/lookup/api-reference/get-users-me Rate limit: 75 requests per 15-minute window per each authenticated user.

func (*Client) NewRequest

func (c *Client) NewRequest(method, path string, payload interface{}) (*http.Request, error)

NewRequest returns a http.Request for the given path. If a payload is provided it will get JSON encoded.

func (*Client) Tweet

func (c *Client) Tweet(tweetID string, params *url.Values) (*Tweet, error)

Tweet returns information about a single Tweet. API: https://developer.twitter.com/en/docs/twitter-api/tweets/lookup/api-reference/get-tweets-id Rate limit: 900 requests per 15-minute window per each authenticated user.

func (*Client) User

func (c *Client) User(id string, params *url.Values) (*User, error)

User returns information about a single user. API: https://developer.twitter.com/en/docs/twitter-api/users/lookup/api-reference/get-users-id Rate limit: 900 requests per 15-minute window per each authenticated user.

type ClientOption

type ClientOption func(*Client)

ClientOption sets some additional options on a client.

func EnableRateLimitRetry

func EnableRateLimitRetry() ClientOption

EnableRateLimitRetry enables wait and retry on 429 responses. Default is false.

func WithBaseURL

func WithBaseURL(url string) ClientOption

WithBaseURL sets the base URL for request.

func WithLogger

func WithLogger(logger Logger) ClientOption

WithLogger sets the logger used in the client. By default no log output is emitted.

type HTTPClient

type HTTPClient interface {
	Do(*http.Request) (*http.Response, error)
}

HTTPClient models the http client interface.

type HTTPError

type HTTPError struct {
	Response       *http.Response
	StatusCode     int
	Status         string
	RateLimitReset time.Time // time when the rate-limiting will reset and it's safe to retry requests
}

HTTPError contains information about a failed http request.

func (*HTTPError) Error

func (e *HTTPError) Error() string

Error returns a string representation of the HTTPError.

type LikingUsersInterator

type LikingUsersInterator struct {
	// contains filtered or unexported fields
}

LikingUsersInterator is used to iterate over liking users results.

func (*LikingUsersInterator) NextPage

func (i *LikingUsersInterator) NextPage() bool

NextPage advances the iterator and returns true if there are more results.

func (*LikingUsersInterator) User

func (i *LikingUsersInterator) User() ([]*User, error)

Users returns the liking users result for the current pagination token.

type Logger

type Logger interface {
	Printf(format string, v ...interface{})
}

Logger is a simple logger interface.

type Tweet

type Tweet struct {
	ID        string    `json:"id"`
	AuthorID  string    `json:"author_id"`
	CreatedAt time.Time `json:"created_at"`
	Text      string    `json:"text"`
}

Tweet data returned from the API.

type User

type User struct {
	ID              string    `json:"id"`
	Name            string    `json:"name"`
	UserName        string    `json:"username"`
	CreatedAt       time.Time `json:"created_at"`
	Description     string    `json:"description"`
	Location        string    `json:"location"`
	PinnedTweetID   string    `json:"pinned_tweet_id"`
	ProfileImageUrl string    `json:"profile_image_url"`
	Protected       bool      `json:"protected"`
	URL             string    `json:"url"`
	Verified        bool      `json:"verified"`
	Withheld        bool      `json:"withheld"`
}

User data returned from the API.

Jump to

Keyboard shortcuts

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