twitter

package
v0.0.0-...-5b2671d Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2018 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ClientTimeout   = 20
	BaseUrlV1       = "https://api.twitter.com/1"
	BaseUrl         = "https://api.twitter.com/1.1"
	UploadBaseUrl   = "https://upload.twitter.com/1.1"
	DEFAULT_DELAY   = 0 * time.Second
	EFAULT_CAPACITY = 5
)
View Source
const (
	//Error code defintions match the Twitter documentation
	//https://developer.twitter.com/en/docs/basics/response-codes
	TwitterErrorCouldNotAuthenticate    = 32
	TwitterErrorDoesNotExist            = 34
	TwitterErrorAccountSuspended        = 64
	TwitterErrorApi1Deprecation         = 68 //This should never be needed
	TwitterErrorRateLimitExceeded       = 88
	TwitterErrorInvalidToken            = 89
	TwitterErrorOverCapacity            = 130
	TwitterErrorInternalError           = 131
	TwitterErrorCouldNotAuthenticateYou = 135
	TwitterErrorStatusIsADuplicate      = 187
	TwitterErrorBadAuthenticationData   = 215
	TwitterErrorUserMustVerifyLogin     = 231

	// Undocumented by Twitter, but may be returned instead of 34
	TwitterErrorDoesNotExist2 = 144
)
View Source
const (
	FilenameDirectMessages = "dms.json"
	FilenameFavorites      = "favorites.json"
	FilenameFollowers      = "followers.json"
	FilenameFriends        = "friends.json"
	FilenameLists          = "lists.json"
	FilenameTimeline       = "tweets.json"
)

Variables

This section is empty.

Functions

func LoadArchive

func LoadArchive(base string) (*twitterpb.Archive, error)

Types

type ApiError

type ApiError struct {
	StatusCode int
	Header     http.Header
	Body       string
	Decoded    TwitterErrorResponse
	URL        *url.URL
}

func (ApiError) Error

func (aerr ApiError) Error() string

ApiError supports the error interface

func (*ApiError) RateLimitCheck

func (aerr *ApiError) RateLimitCheck() (isRateLimitError bool, nextWindow time.Time)

Check to see if an error is a Rate Limiting error. If so, find the next available window in the header. Use like so:

   if aerr, ok := err.(*ApiError); ok {
		  if isRateLimitError, nextWindow := aerr.RateLimitCheck(); isRateLimitError {
			<-time.After(nextWindow.Sub(time.Now()))
		  }
   }

type Archiver

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

func NewArchiver

func NewArchiver(c *toml.Tree) (*Archiver, error)

func (*Archiver) Sync

func (a *Archiver) Sync(ctx context.Context) error

type CSVTweet

type CSVTweet struct {
	TweetID                  int64
	InReplyToStatusID        int64
	InReplyToUserID          int64
	Timestamp                time.Time
	Source                   string
	Text                     string
	RetweetedStatusID        int64
	RetweetedStatusUserID    int64
	RetweetedStatusTimestamp time.Time
	ExpandedURLs             []string
}

type DirectMessageEventsResp

type DirectMessageEventsResp struct {
	NextCursor string                          `json:"next_cursor"`
	Events     []*twitterpb.DirectMessageEvent `json:"events"`
}

"{\"type\":\"message_create\",\"id\":\"1005146433668841476\",\"created_timestamp\":\"1528480559161\",\"message_create\":{\"target\":{\"recipient_id\":\"86892924\"},\"sender_id\":\"160248151\",\"source_app_id\":\"268278\",\"message_data\":{\"text\":\"Sorry for the random Twitter message, I need to test out the DM API\",\"entities\":{\"hashtags\":[],\"symbols\":[],\"user_mentions\":[],\"urls\":[]}}}}"

type ListsOwnershipsResp

type ListsOwnershipsResp struct {
	NextCursor     string           `json:"next_cursor_str"`
	PreviousCursor string           `json:"previous_cursor_str"`
	Lists          []twitterpb.List `json:"lists"`
}

type Reader

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

func NewCSVReader

func NewCSVReader(in io.Reader) *Reader

func (*Reader) Read

func (c *Reader) Read() (r CSVTweet, err error)

type TwitterApi

type TwitterApi struct {
	Credentials *oauth.Credentials
	HttpClient  *http.Client
	// contains filtered or unexported fields
}

func NewTwitterApi

func NewTwitterApi(access_token, access_token_secret, consumer_key, consumer_secret string) *TwitterApi

NewTwitterApi takes an user-specific access token and secret and returns a TwitterApi struct for that user. The TwitterApi struct can be used for accessing any of the endpoints available.

func (TwitterApi) GetDirectMessageEvents

func (a TwitterApi) GetDirectMessageEvents(params url.Values) (DirectMessageEventsResp, error)

func (TwitterApi) GetFavorites

func (a TwitterApi) GetFavorites(params url.Values) ([]*twitterpb.Tweet, error)

func (TwitterApi) GetFollowers

func (a TwitterApi) GetFollowers(params url.Values) (UsersResp, error)

func (TwitterApi) GetFriends

func (a TwitterApi) GetFriends(params url.Values) (UsersResp, error)

func (TwitterApi) GetListsOwnedBy

func (a TwitterApi) GetListsOwnedBy(params url.Values) (ListsOwnershipsResp, error)

func (TwitterApi) GetMembers

func (a TwitterApi) GetMembers(params url.Values) (UsersResp, error)

func (TwitterApi) GetUserTimeline

func (a TwitterApi) GetUserTimeline(params url.Values) ([]*twitterpb.Tweet, error)

func (TwitterApi) LookupStatuses

func (a TwitterApi) LookupStatuses(params url.Values) ([]*twitterpb.Tweet, error)

func (*TwitterApi) SetDelay

func (c *TwitterApi) SetDelay(t time.Duration)

SetDelay will set the delay between throttled queries To turn of throttling, set it to 0 seconds

type TwitterError

type TwitterError struct {
	Message string `json:"message"`
	Code    int    `json:"code"`
}

TwitterError represents a single Twitter error messages/code pair

func (TwitterError) Error

func (te TwitterError) Error() string

type TwitterErrorResponse

type TwitterErrorResponse struct {
	Errors []TwitterError `json:"errors"`
}

TwitterErrorResponse has an array of Twitter error messages It satisfies the "error" interface For the most part, Twitter seems to return only a single error message Currently, we assume that this always contains exactly one error message

func (TwitterErrorResponse) Error

func (tr TwitterErrorResponse) Error() string

func (TwitterErrorResponse) First

func (tr TwitterErrorResponse) First() error

type UsersResp

type UsersResp struct {
	NextCursor     string           `json:"next_cursor_str"`
	PreviousCursor string           `json:"previous_cursor_str"`
	Users          []twitterpb.User `json:"users"`
}

Jump to

Keyboard shortcuts

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