twitter

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

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

Go to latest
Published: Mar 6, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const TWITTER_OAUTH_TOKEN_URL = "https://api.twitter.com/2/oauth2/token"

Variables

This section is empty.

Functions

This section is empty.

Types

type Authorizer

type Authorizer interface {
	Add(*http.Request)
}

Authorizer will add the authorization to the HTTP request

type Client

type Client struct {
	ConsumerKey, ConsumerSecret, AccessToken, AccessSecret string
	OauthClientId                                          string
	OauthClientSecret                                      string
	RedirectUri                                            string
	RedirectUriForInternal                                 string
	AppTokenForInternal                                    string
	AppToken                                               string
	// contains filtered or unexported fields
}

func NewClient

func NewClient(appToken, consumerKey, consumerSecret, accessToken, accessSecret, oauthClientId, oauthClientSecret, redirectUri string) *Client

func NewTwitterWrapClient

func NewTwitterWrapClient(accessToken string) *Client

func (*Client) CheckIfTweetIsTruncated

func (c *Client) CheckIfTweetIsTruncated(tweetText string) bool

func (*Client) FetchReferencedTweetByIDs

func (c *Client) FetchReferencedTweetByIDs(tweetIDMap map[string]bool) (map[string]*TweetResp, error)

func (*Client) GetAllUserTweets

func (c *Client) GetAllUserTweets(userTwitterID, paginationToken, accessToken string, maxResults int) (*UserTimeline, error)

func (*Client) GetListFollowing

func (c *Client) GetListFollowing(userTwitterID, paginationToken, accessToken string) (*UserFollowLookup, error)

func (*Client) GetListUserMentions

func (c *Client) GetListUserMentions(userTwitterID, paginationToken, accessToken string, maxResults int) (*UserTimeline, error)

func (*Client) GetListUserTweets

func (c *Client) GetListUserTweets(userTwitterID, paginationToken, accessToken string, maxResults int) (*UserTimeline, error)

func (*Client) GetTweetDetails

func (c *Client) GetTweetDetails(tweetIDs []string) (map[string]*TweetResp, error)

func (*Client) GetTweetFullText

func (c *Client) GetTweetFullText(tweetID string) (*TweetFullTextResponse, error)

func (*Client) GetTweetsByUser

func (c *Client) GetTweetsByUser(userID string, cursor string) (map[string]*TweetResp, string, error)

func (*Client) GetTwitterAccessToken

func (c *Client) GetTwitterAccessToken(refreshToken string) (*TwitterTokenResponse, error)

func (*Client) GetTwitterAccessTokenWithKey

func (c *Client) GetTwitterAccessTokenWithKey(clientID, clientSecret, refreshToken string) (*TwitterTokenResponse, error)

func (*Client) GetTwitterByID

func (c *Client) GetTwitterByID(userTwitterID string) (*UserObj, error)

func (*Client) GetTwitterByUserName

func (c *Client) GetTwitterByUserName(userName string) (*UserObj, error)

get user info

func (*Client) GetTwitterMe

func (c *Client) GetTwitterMe(accessToken string) (*UserObj, error)

func (*Client) GetTwitterOAuthToken

func (c *Client) GetTwitterOAuthToken(code string, callbackUrl, address, agentID string) (*TwitterTokenResponse, error)

func (*Client) GetTwitterOAuthTokenWithKey

func (c *Client) GetTwitterOAuthTokenWithKey(clientID, clientSecret, code string, callbackUrl, address, agentID string) (*TwitterTokenResponse, error)

func (*Client) GetTwitterOAuthTokenWithKeyForCreateAgent

func (c *Client) GetTwitterOAuthTokenWithKeyForCreateAgent(clientID, clientSecret, code string, callbackUrl, address string) (*TwitterTokenResponse, error)

func (*Client) GetTwitterOAuthTokenWithKeyForDeveloper

func (c *Client) GetTwitterOAuthTokenWithKeyForDeveloper(clientID, clientSecret, code string, callbackUrl, address string) (*TwitterTokenResponse, error)
func (c *Client) GetTwitterOAuthTokenWithKeyForRelink(clientID, clientSecret, code string, callbackUrl, address string) (*TwitterTokenResponse, error)

func (*Client) GetTwitterUserInfoByToken

func (c *Client) GetTwitterUserInfoByToken(username string) (*TwitterUser, error)

func (*Client) GetTwitterUserInfoID

func (c *Client) GetTwitterUserInfoID(userTwitterID string) (*TwitterUser, error)

func (*Client) LookupTweetsByID

func (c *Client) LookupTweetsByID(accessToken string, tweetID string) (*TweetObj, error)

func (*Client) LookupUserTweets

func (c *Client) LookupUserTweets(accessToken string, tweetIDs []string) (*TweetLookups, error)

func (*Client) LookupUsername

func (c *Client) LookupUsername(accessToken string, usernames []string) (*UserLookups, error)

func (*Client) PostTweet

func (c *Client) PostTweet(tweetContent, imageURL string, additionalOwners []string) error

func (*Client) PostTweetWithVideo

func (c *Client) PostTweetWithVideo(tweetContent, videoURL string, additionalOwners []string) error

func (*Client) ReplyToTweet

func (c *Client) ReplyToTweet(tweetID, replyContent, imageURL string, additionalOwners []string) error

func (*Client) SearchRecentTweet

func (c *Client) SearchRecentTweet(query, paginationToken, accessToken string, maxResult int) (*TweetRecentSearch, error)

func (*Client) SearchRecentTweetV1

func (c *Client) SearchRecentTweetV1(query, sinceID string, accessToken string, maxResult int) (*TweetRecentSearch, error)

func (*Client) SearchUsers

func (c *Client) SearchUsers(query, paginationToken, accessToken string) ([]*UserObj, error)

func (*Client) TwitterOauthCallbackForInternalData

func (c *Client) TwitterOauthCallbackForInternalData(clientID, clientSecret, code, callbackUrl string) (*TwitterTokenResponse, error)

func (*Client) TwitterOauthCallbackForSampleApp

func (c *Client) TwitterOauthCallbackForSampleApp(clientID, clientSecret, code, redirectUri string) (*TwitterTokenResponse, error)

func (*Client) UploadImage

func (c *Client) UploadImage(imageURL string, additionalOwners []string) (string, error)

func (*Client) UploadVideo

func (c *Client) UploadVideo(videoURL string, additionalOwners []string) (string, error)

UploadVideo uploads the video in chunks to Twitter

type EntitiesObj

type EntitiesObj struct {
	Annotations []EntityAnnotationObj `json:"annotations"`
	URLs        []EntityURLObj        `json:"urls"`
	HashTags    []EntityTagObj        `json:"hashtags"`
	Mentions    []EntityMentionObj    `json:"mentions"`
	CashTags    []EntityTagObj        `json:"cashtags"`
}

EntitiesObj contains details about text that has a special meaning.

type EntityAnnotationObj

type EntityAnnotationObj struct {
	EntityObj
	Probability    float64 `json:"probability"`
	Type           string  `json:"type"`
	NormalizedText string  `json:"normalized_text"`
}

EntityAnnotationObj contains details about annotations relative to the text.

type EntityMentionObj

type EntityMentionObj struct {
	EntityObj
	UserName string `json:"username"`
}

EntityMentionObj contains details about text recognized as a user mention.

type EntityObj

type EntityObj struct {
	Start int `json:"start"`
	End   int `json:"end"`
}

EntityObj contains the start and end positions of the text

type EntityTagObj

type EntityTagObj struct {
	EntityObj
	Tag string `json:"tag"`
}

EntityTagObj contains details about text recognized as a tag

type EntityURLObj

type EntityURLObj struct {
	EntityObj
	URL         string `json:"url"`
	ExpandedURL string `json:"expanded_url"`
	DisplayURL  string `json:"display_url"`
	Status      int    `json:"status"`
	Title       string `json:"title"`
	Desription  string `json:"description"`
	UnwoundURL  string `json:"unwound_url"`
}

EntityURLObj contains details about text recognized as a URL.

type ErrorObj

type ErrorObj struct {
	Title        string `json:"title"`
	Detail       string `json:"detail"`
	Type         string `json:"type"`
	ResourceType string `json:"resource_type"`
	Value        string `json:"value"`
	Parameter    string `json:"parameter"`
}

ErrorObj is part of the partial errors in the response

type Exclude

type Exclude string

Exclude used in the timeline parameters

const (
	// ExcludeRetweets will exclude the tweet retweets
	ExcludeRetweets Exclude = "retweets"
	// ExcludeReplies will exclude the tweet replies
	ExcludeReplies Exclude = "replies"
)

type Expansion

type Expansion string

Expansion can expand objects referenced in the payload

const (
	// ExpansionAttachmentsPollIDs returns a poll object containing metadata for the poll included in the Tweet
	ExpansionAttachmentsPollIDs Expansion = "attachments.poll_ids"
	// ExpansionAttachmentsMediaKeys returns a media object representing the images, videos, GIFs included in the Tweet
	ExpansionAttachmentsMediaKeys Expansion = "attachments.media_keys"
	// ExpansionAuthorID returns a user object representing the Tweet’s author
	ExpansionAuthorID Expansion = "author_id"
	// ExpansionEntitiesMentionsUserName returns a user object for the user mentioned in the Tweet
	ExpansionEntitiesMentionsUserName Expansion = "entities.mentions.username"
	// ExpansionGeoPlaceID returns a place object containing metadata for the location tagged in the Tweet
	ExpansionGeoPlaceID Expansion = "geo.place_id"
	// ExpansionInReplyToUserID returns a user object representing the Tweet author this requested Tweet is a reply of
	ExpansionInReplyToUserID Expansion = "in_reply_to_user_id"
	// ExpansionReferencedTweetsID returns a Tweet object that this Tweet is referencing (either as a Retweet, Quoted Tweet, or reply)
	ExpansionReferencedTweetsID Expansion = "referenced_tweets.id"
	// ExpansionReferencedTweetsIDAuthorID returns a user object for the author of the referenced Tweet
	ExpansionReferencedTweetsIDAuthorID Expansion = "referenced_tweets.id.author_id"
	// ExpansionPinnedTweetID returns a Tweet object representing the Tweet pinned to the top of the user’s profile
	ExpansionPinnedTweetID Expansion = "pinned_tweet_id"
)

type HTTPError

type HTTPError struct {
	Status     string
	StatusCode int
	URL        string
}

HTTPError is a response error where the body is not JSON, but XML. This commonly seen in 404 errors.

func (*HTTPError) Error

func (h *HTTPError) Error() string

type MediaField

type MediaField string

MediaField can expand the fields that are returned in the media object

const (
	// MediaFieldDurationMS available when type is video. Duration in milliseconds of the video.
	MediaFieldDurationMS MediaField = "duration_ms"
	// MediaFieldHeight of this content in pixels.
	MediaFieldHeight MediaField = "height"
	// MediaFieldMediaKey unique identifier of the expanded media content.
	MediaFieldMediaKey MediaField = "media_key"
	// MediaFieldPreviewImageURL is the URL to the static placeholder preview of this content.
	MediaFieldPreviewImageURL MediaField = "preview_image_url"
	// MediaFieldType is the type of content (animated_gif, photo, video)
	MediaFieldType MediaField = "type"
	// MediaFieldURL is the URL of the content
	MediaFieldURL MediaField = "url"
	// MediaFieldWidth is the width of this content in pixels
	MediaFieldWidth MediaField = "width"
	// MediaFieldPublicMetrics is the public engagement metrics for the media content at the time of the request.
	MediaFieldPublicMetrics MediaField = "public_metrics"
	// MediaFieldNonPublicMetrics is the non-public engagement metrics for the media content at the time of the request.
	MediaFieldNonPublicMetrics MediaField = "non_public_metrics"
	// MediaFieldOrganicMetrics is the engagement metrics for the media content, tracked in an organic context, at the time of the request.
	MediaFieldOrganicMetrics MediaField = "organic_metrics"
	// MediaFieldPromotedMetrics is the URL to the static placeholder preview of this content.
	MediaFieldPromotedMetrics MediaField = "promoted_metrics"
)

type MediaMetricsObj

type MediaMetricsObj struct {
	Playback0   int `json:"playback_0_count"`
	Playback100 int `json:"playback_100_count"`
	Playback25  int `json:"playback_25_count"`
	Playback50  int `json:"playback_50_count"`
	Playback75  int `json:"playback_75_count"`
	Views       int `json:"view_count"`
}

MediaMetricsObj engagement metrics for the media content at the time of the request

type MediaObj

type MediaObj struct {
	Key              string          `json:"media_key"`
	Type             string          `json:"type"`
	URL              string          `json:"url"`
	DurationMS       int             `json:"duration_ms"`
	Height           int             `json:"height"`
	NonPublicMetrics MediaMetricsObj `json:"non_public_metrics"`
	OrganicMetrics   MediaMetricsObj `json:"organic_metrics"`
	PreviewImageURL  string          `json:"preview_image_url"`
	PromotedMetrics  MediaMetricsObj `json:"promoted_metrics"`
	PublicMetrics    MediaMetricsObj `json:"public_metrics"`
	Width            int             `json:"width"`
}

MediaObj refers to any image, GIF, or video attached to a Tweet

type Mention

type Mention struct {
	Username string `json:"username"`
	UserID   string `json:"user_id"`
}

type PlaceField

type PlaceField string

PlaceField can expand the tweet primary object

const (
	// PlaceFieldContainedWithin returns the identifiers of known places that contain the referenced place.
	PlaceFieldContainedWithin PlaceField = "contained_within"
	// PlaceFieldCountry is the full-length name of the country this place belongs to.
	PlaceFieldCountry PlaceField = "country"
	// PlaceFieldCountryCode is the ISO Alpha-2 country code this place belongs to.
	PlaceFieldCountryCode PlaceField = "country_code"
	// PlaceFieldFullName is a longer-form detailed place name.
	PlaceFieldFullName PlaceField = "full_name"
	// PlaceFieldGeo contains place details in GeoJSON format.
	PlaceFieldGeo PlaceField = "geo"
	// PlaceFieldID is the unique identifier of the expanded place, if this is a point of interest tagged in the Tweet.
	PlaceFieldID PlaceField = "id"
	// PlaceFieldName is the short name of this place
	PlaceFieldName PlaceField = "name"
	// PlaceFieldPlaceType is specified the particular type of information represented by this place information, such as a city name, or a point of interest.
	PlaceFieldPlaceType PlaceField = "place_type"
)

type PlaceGeoObj

type PlaceGeoObj struct {
	Type       string                 `json:"type"`
	BBox       []float64              `json:"bbox"`
	Properties map[string]interface{} `json:"properties"`
}

PlaceGeoObj contains place details

type PlaceObj

type PlaceObj struct {
	FullName        string      `json:"full_name"`
	ID              string      `json:"id"`
	ContainedWithin []string    `json:"contained_within"`
	Country         string      `json:"country"`
	CountryCode     string      `json:"country_code"`
	Geo             PlaceGeoObj `json:"geo"`
	Name            string      `json:"name"`
	PlaceType       string      `json:"place_type"`
}

PlaceObj tagged in a Tweet is not a primary object on any endpoint

type PollField

type PollField string

PollField defines the fields of the expanded tweet

const (
	// PollFieldDurationMinutes specifies the total duration of this poll.
	PollFieldDurationMinutes PollField = "duration_minutes"
	// PollFieldEndDateTime specifies the end date and time for this poll.
	PollFieldEndDateTime PollField = "end_datetime"
	// PollFieldID is unique identifier of the expanded poll.
	PollFieldID PollField = "id"
	// PollFieldOptions contains objects describing each choice in the referenced poll.
	PollFieldOptions PollField = "options"
	// PollFieldVotingStatus indicates if this poll is still active and can receive votes, or if the voting is now closed.
	PollFieldVotingStatus PollField = "voting_status"
)

type PollObj

type PollObj struct {
	ID              string          `json:"id"`
	Options         []PollOptionObj `json:"options"`
	DurationMinutes int             `json:"duration_minutes"`
	EndDateTime     string          `json:"end_datetime"`
	VotingStatus    string          `json:"voting_status"`
}

PollObj included in a Tweet is not a primary object on any endpoint

type PollOptionObj

type PollOptionObj struct {
	Position int    `json:"position"`
	Label    string `json:"label"`
	Votes    int    `json:"votes"`
}

PollOptionObj contains objects describing each choice in the referenced poll.

type TrendsResp

type TrendsResp struct {
	TrendName  string `json:"trend_name"`
	TweetCount uint   `json:"tweet_count"`
}

type Tweet

type Tweet struct {
	Authorizer Authorizer
	Client     *http.Client
	Host       string
}

Tweet represents the Tweet v2 APIs

func (*Tweet) ApplyFilteredStreamRules

func (t *Tweet) ApplyFilteredStreamRules(ctx context.Context, rules TweetSearchStreamRule, validate bool) (*TweetSearchStreamRules, error)

ApplyFilteredStreamRules will add and/or remove rules from the seach stream

func (*Tweet) FilteredStream

func (t *Tweet) FilteredStream(ctx context.Context, options TweetFieldOptions) (TweetLookups, error)

FilteredStream allows to stream some tweets on a specific set of filter rules

func (*Tweet) FilteredStreamRules

func (t *Tweet) FilteredStreamRules(ctx context.Context, ids []string) (*TweetSearchStreamRules, error)

FilteredStreamRules will return the rules from the ids

func (*Tweet) HideReplies

func (t *Tweet) HideReplies(ctx context.Context, id string, hidden bool) error

HideReplies will hide a tweet id replies

func (*Tweet) Lookup

func (t *Tweet) Lookup(ctx context.Context, ids []string, options TweetFieldOptions) (TweetLookups, error)

Lookup will return a tweet or tweets from a set of ids

func (*Tweet) RecentSearch

func (t *Tweet) RecentSearch(ctx context.Context, query string, searchOpts TweetRecentSearchOptions, fieldOpts TweetFieldOptions) (*TweetRecentSearch, error)

RecentSearch will query the recent search

func (*Tweet) SampledStream

func (t *Tweet) SampledStream(ctx context.Context, options TweetFieldOptions) (TweetLookups, error)

SampledStream will stream about 1% of all tweets

type TweetAttachmentsObj

type TweetAttachmentsObj struct {
	MediaKeys []string `json:"media_keys"`
	PollIDs   []string `json:"poll_ids"`
}

TweetAttachmentsObj specifics the type of attachment present in the tweet

type TweetContextAnnotationObj

type TweetContextAnnotationObj struct {
	Domain TweetContextObj `json:"domain"`
	Entity TweetContextObj `json:"entity"`
}

TweetContextAnnotationObj contain the context annotation

type TweetContextObj

type TweetContextObj struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
}

TweetContextObj contains the elements which identify detailed information regarding the domain classificaiton based on the Tweet text

type TweetError

type TweetError struct {
	Parameters interface{} `json:"parameters"`
	Message    string      `json:"message"`
}

TweetError is the group of errors in a response

type TweetErrorResponse

type TweetErrorResponse struct {
	StatusCode int
	Errors     []TweetError `json:"errors"`
	Title      string       `json:"title"`
	Detail     string       `json:"detail"`
	Type       string       `json:"type"`
}

TweetErrorResponse is the error message from the callout

func (*TweetErrorResponse) Error

func (t *TweetErrorResponse) Error() string

type TweetField

type TweetField string

TweetField defines the fields of the basic building block of all things twitter

const (
	// TweetFieldID is the unique identifier of the requested Tweet.
	TweetFieldID TweetField = "id"
	// TweetFieldText is the actual UTF-8 text of the Tweet. See twitter-text for details on what characters are currently considered valid.
	TweetFieldText TweetField = "text"

	TweetFieldNoteText TweetField = "note_tweet"

	// TweetFieldAttachments specifies the type of attachments (if any) present in this Tweet.
	TweetFieldAttachments TweetField = "attachments"
	// TweetFieldAuthorID is the unique identifier of the User who posted this Tweet
	TweetFieldAuthorID TweetField = "author_id"
	// TweetFieldContextAnnotations contains context annotations for the Tweet.
	TweetFieldContextAnnotations TweetField = "context_annotations"
	// TweetFieldConversationID is the Tweet ID of the original Tweet of the conversation (which includes direct replies, replies of replies).
	TweetFieldConversationID TweetField = "conversation_id"
	// TweetFieldCreatedAt is the creation time of the Tweet.
	TweetFieldCreatedAt TweetField = "created_at"
	// TweetFieldEntities are the entities which have been parsed out of the text of the Tweet. Additionally see entities in Twitter Objects.
	TweetFieldEntities TweetField = "entities"
	// TweetFieldGeo contains details about the location tagged by the user in this Tweet, if they specified one.
	TweetFieldGeo TweetField = "geo"
	// TweetFieldInReplyToUserID will contain the original Tweet’s author ID
	TweetFieldInReplyToUserID TweetField = "in_reply_to_user_id"
	// TweetFieldLanguage is the language of the Tweet, if detected by Twitter. Returned as a BCP47 language tag.
	TweetFieldLanguage TweetField = "lang"
	// TweetFieldNonPublicMetrics are the non-public engagement metrics for the Tweet at the time of the request.
	TweetFieldNonPublicMetrics TweetField = "non_public_metrics"
	// TweetFieldPublicMetrics are the public engagement metrics for the Tweet at the time of the request.
	TweetFieldPublicMetrics TweetField = "public_metrics"
	// TweetFieldOrganicMetrics are the engagement metrics, tracked in an organic context, for the Tweet at the time of the request.
	TweetFieldOrganicMetrics TweetField = "organic_metrics"
	// TweetFieldPromotedMetrics are the engagement metrics, tracked in a promoted context, for the Tweet at the time of the request.
	TweetFieldPromotedMetrics TweetField = "promoted_metrics"
	// TweetFieldPossiblySensitve is an indicator that the URL contained in the Tweet may contain content or media identified as sensitive content.
	TweetFieldPossiblySensitve TweetField = "possibly_sensitive"
	// TweetFieldReferencedTweets is a list of Tweets this Tweet refers to.
	TweetFieldReferencedTweets TweetField = "referenced_tweets"
	// TweetFieldSource is the name of the app the user Tweeted from.
	TweetFieldSource TweetField = "source"
	// TweetFieldWithHeld contains withholding details
	TweetFieldWithHeld TweetField = "withheld"
)

type TweetFieldOptions

type TweetFieldOptions struct {
	Expansions  []Expansion
	MediaFields []MediaField
	PlaceFields []PlaceField
	PollFields  []PollField
	TweetFields []TweetField
	UserFields  []UserField
}

TweetFieldOptions are the tweet options for the response

type TweetFullTextResponse

type TweetFullTextResponse struct {
	Data struct {
		ID                  string   `json:"id"`
		Text                string   `json:"text"`
		EditHistoryTweetIDs []string `json:"edit_history_tweet_ids"`
		NoteTweet           struct {
			Text string `json:"text"`
		} `json:"note_tweet"`
	} `json:"data"`
}

type TweetGeoCoordinatesObj

type TweetGeoCoordinatesObj struct {
	Type        string    `json:"type"`
	Coordinates []float64 `json:"coordinates"`
}

TweetGeoCoordinatesObj contains details about the coordinates of the location tagged by the user in this Tweet, if they specified one.

type TweetGeoObj

type TweetGeoObj struct {
	PlaceID     string                 `json:"place_id"`
	Coordinates TweetGeoCoordinatesObj `json:"coordinates"`
}

TweetGeoObj contains details about the location tagged by the user in this Tweet, if they specified one.

type TweetLookup

type TweetLookup struct {
	Tweet            TweetObj
	Media            *MediaObj
	Place            *PlaceObj
	Poll             *PollObj
	User             *UserObj
	InReplyUser      *UserObj
	Mentions         []*UserObj
	AttachmentPolls  []*PollObj
	AttachmentMedia  []*MediaObj
	ReferencedTweets []TweetLookup
}

TweetLookup is a complete tweet objects

type TweetLookups

type TweetLookups map[string]TweetLookup

TweetLookups is .a map of tweet lookups

type TweetMetricsObj

type TweetMetricsObj struct {
	Impressions       int `json:"impression_count"`
	URLLinkClicks     int `json:"url_link_clicks"`
	UserProfileClicks int `json:"user_profile_clicks"`
	Likes             int `json:"like_count"`
	Replies           int `json:"reply_count"`
	Retweets          int `json:"retweet_count"`
	Quotes            int `json:"quote_count"`
}

TweetMetricsObj engagement metrics for the Tweet at the time of the request

type TweetObj

type TweetObj struct {
	ID                 string                      `json:"id"`
	Text               string                      `json:"text"`
	Attachments        TweetAttachmentsObj         `json:"attachments"`
	AuthorID           string                      `json:"author_id"`
	ContextAnnotations []TweetContextAnnotationObj `json:"context_annotations"`
	ConversationID     string                      `json:"conversation_id"`
	CreatedAt          string                      `json:"created_at"`
	Entities           EntitiesObj                 `json:"entities"`
	Geo                TweetGeoObj                 `json:"geo"`
	InReplyToUserID    string                      `json:"in_reply_to_user_id"`
	Language           string                      `json:"lang"`
	NonPublicMetrics   TweetMetricsObj             `json:"non_public_metrics"`
	OrganicMetrics     TweetMetricsObj             `json:"organic_metrics"`
	PossibySensitive   bool                        `json:"possiby_sensitive"`
	PromotedMetrics    TweetMetricsObj             `json:"promoted_metrics"`
	PublicMetrics      TweetMetricsObj             `json:"public_metrics"`
	ReferencedTweets   []TweetReferencedTweetObj   `json:"referenced_tweets"`
	Source             string                      `json:"source"`
	WithHeld           WithHeldObj                 `json:"withheld"`
	NoteTweet          struct {
		Text string `json:"text"`
	} `json:"note_tweet"`
}

TweetObj is the primary object on the tweets endpoints

func (*TweetObj) GetFullText

func (tw *TweetObj) GetFullText() string

type TweetRecentSearch

type TweetRecentSearch struct {
	LookUps TweetLookups
	Meta    TweetRecentSearchMeta
}

TweetRecentSearch is what is returned from the callout

func (*TweetRecentSearch) UnmarshalJSON

func (t *TweetRecentSearch) UnmarshalJSON(b []byte) error

UnmarshalJSON will unmarshal the byte array

type TweetRecentSearchMeta

type TweetRecentSearchMeta struct {
	NewestID    string `json:"newest_id"`
	OldestID    string `json:"oldest_id"`
	ResultCount int    `json:"result_count"`
	NextToken   string `json:"next_token"`
}

TweetRecentSearchMeta is the media data returned from the recent search

type TweetRecentSearchOptions

type TweetRecentSearchOptions struct {
	StartTime time.Time
	EndTime   time.Time
	MaxResult int
	NextToken string
	SinceID   string
	UntilID   string
	// contains filtered or unexported fields
}

TweetRecentSearchOptions handles all of the recent search parameters

type TweetReferencedTweetObj

type TweetReferencedTweetObj struct {
	Type string `json:"type"`
	ID   string `json:"id"`
}

TweetReferencedTweetObj is a Tweet this Tweet refers to

type TweetResp

type TweetResp struct {
	ID              string    `json:"id"`
	Text            string    `json:"text"`
	AuthorID        string    `json:"author_id"`
	AuthorUsername  string    `json:"author_username,omitempty"`
	AuthorName      string    `json:"author_name,omitempty"`
	CreatedAt       time.Time `json:"created_at"`
	Language        string    `json:"lang"`
	LikeCount       int       `json:"like_count"`
	RetweetCount    int       `json:"retweet_count"`
	ReplyCount      int       `json:"reply_count"`
	QuoteCount      int       `json:"quote_count"`
	ImpressionCount int       `json:"impression_count"`
	InReplyToUserID string    `json:"in_reply_to_user_id,omitempty"`
	FollowersCount  uint      `json:"followers_count,omitempty"`

	// Reply-related fields
	IsReply          bool   `json:"is_reply"`
	InReplyToTweetID string `json:"in_reply_to_tweet_id,omitempty"`
	OriginalText     string `json:"original_text,omitempty"`

	// Retweet-related fields
	IsRetweet     bool   `json:"is_retweet"`
	RepostTweetID string `json:"repost_tweet_id,omitempty"`
	RepostText    string `json:"repost_text,omitempty"`

	// Quote-related fields
	IsQuote      bool   `json:"is_quote"`
	QuoteTweetID string `json:"quote_tweet_id,omitempty"`
	QuoteText    string `json:"quote_text,omitempty"`

	// New field for mentions
	Mentions []Mention `json:"mentions,omitempty"`

	ParentTweetID        string
	ParentAuthorUsername string `json:"parent_author_username,omitempty"`
	ParentAuthorID       string `json:"parent_author_id,omitempty"`
}

func (*TweetResp) IsMention

func (m *TweetResp) IsMention(username string) bool

type TweetSearchStreamAddRule

type TweetSearchStreamAddRule struct {
	Value string `json:"value"`
	Tag   string `json:"tag,omitempty"`
}

TweetSearchStreamAddRule are the rules to add the search stream

type TweetSearchStreamDeleteRule

type TweetSearchStreamDeleteRule struct {
	IDs []string `json:"ids"`
}

TweetSearchStreamDeleteRule lists the search rule ids to remove

type TweetSearchStreamRule

type TweetSearchStreamRule struct {
	Add    []*TweetSearchStreamAddRule  `json:"add,omitempty"`
	Delete *TweetSearchStreamDeleteRule `json:"delete,omitempty"`
}

TweetSearchStreamRule are the rules to add and/or delete

type TweetSearchStreamRuleData

type TweetSearchStreamRuleData struct {
	ID    string `json:"id"`
	Value string `json:"value"`
	Tag   string `json:"tag"`
}

TweetSearchStreamRuleData are the rules that where added

type TweetSearchStreamRuleMeta

type TweetSearchStreamRuleMeta struct {
	Sent    string                       `json:"sent"`
	Summary TweetSearchStreamRuleSummary `json:"summary"`
}

TweetSearchStreamRuleMeta is the meta data for the search rules

type TweetSearchStreamRuleSummary

type TweetSearchStreamRuleSummary struct {
	Created    int `json:"created"`
	NotCreated int `json:"not_created"`
	Deleted    int `json:"deleted"`
	NotDeleted int `json:"not_deleted"`
}

TweetSearchStreamRuleSummary is the summary of the rules

type TweetSearchStreamRules

type TweetSearchStreamRules struct {
	Data []TweetSearchStreamRuleData `json:"data"`
	Meta TweetSearchStreamRuleMeta   `json:"meta"`
}

TweetSearchStreamRules is the returned set of rules

type TwitterMeResp

type TwitterMeResp struct {
	UserObj UserObj `json:"data"`
}

type TwitterTokenResponse

type TwitterTokenResponse struct {
	TokenType    string `json:"token_type"`
	ExpiresIn    int    `json:"expires_in"`
	AccessToken  string `json:"access_token"`
	Scope        string `json:"scope"`
	RefreshToken string `json:"refresh_token"`
}

type TwitterUser

type TwitterUser struct {
	TwitterID       string
	TwitterUsername string
	Name            string
	ProfileUrl      string `gorm:"type:text collate utf8mb4_unicode_ci"`
	FollowersCount  uint
	FollowingsCount uint
	IsBlueVerified  bool
	CreatedAt       time.Time
}

type User

type User struct {
	Authorizer Authorizer
	Client     *http.Client
	Host       string
}

User represents the User v2 APIs

func (*User) Lookup

func (u *User) Lookup(ctx context.Context, ids []string, fieldOpts UserFieldOptions) (UserLookups, error)

Lookup can be used to look up a user by their id

func (*User) LookupFollowers

func (u *User) LookupFollowers(ctx context.Context, id string, followOpts UserFollowOptions) (*UserFollowLookup, error)

LookupFollowers will return a users followers

func (*User) LookupFollowing

func (u *User) LookupFollowing(ctx context.Context, id string, followOpts UserFollowOptions) (*UserFollowLookup, error)

LookupFollowing handles the user following callout

func (*User) LookupUsername

func (u *User) LookupUsername(ctx context.Context, usernames []string, fieldOpts UserFieldOptions) (UserLookups, error)

LookupUsername will retuen the user information from its user names

func (*User) Mentions

func (u *User) Mentions(ctx context.Context, id string, tweetOpts UserTimelineOpts) (*UserTimeline, error)

Mentions will return back the user tweets mentions timeline

func (*User) Tweets

func (u *User) Tweets(ctx context.Context, id string, tweetOpts UserTimelineOpts) (*UserTimeline, error)

Tweets is the user timeline tweets

type UserField

type UserField string

UserField defines the twitter user account metadata fields

const (
	// UserFieldCreatedAt is the UTC datetime that the user account was created on Twitter.
	UserFieldCreatedAt UserField = "created_at"
	// UserFieldDescription is the text of this user's profile description (also known as bio), if the user provided one.
	UserFieldDescription UserField = "description"
	// UserFieldEntities contains details about text that has a special meaning in the user's description.
	UserFieldEntities UserField = "entities"
	// UserFieldID is the unique identifier of this user.
	UserFieldID UserField = "id"
	// UserFieldLocation is the location specified in the user's profile, if the user provided one.
	UserFieldLocation UserField = "location"
	// UserFieldName is the name of the user, as they’ve defined it on their profile
	UserFieldName UserField = "name"
	// UserFieldPinnedTweetID is the unique identifier of this user's pinned Tweet.
	UserFieldPinnedTweetID UserField = "pinned_tweet_id"
	// UserFieldProfileImageURL is the URL to the profile image for this user, as shown on the user's profile.
	UserFieldProfileImageURL UserField = "profile_image_url"
	// UserFieldProtected indicates if this user has chosen to protect their Tweets (in other words, if this user's Tweets are private).
	UserFieldProtected UserField = "protected"
	// UserFieldPublicMetrics contains details about activity for this user.
	UserFieldPublicMetrics UserField = "public_metrics"
	// UserFieldURL is the URL specified in the user's profile, if present.
	UserFieldURL UserField = "url"
	// UserFieldUserName is the Twitter screen name, handle, or alias that this user identifies themselves with
	UserFieldUserName UserField = "username"
	// UserFieldVerified indicates if this user is a verified Twitter User.
	UserFieldVerified UserField = "verified"
	// UserFieldWithHeld contains withholding details
	UserFieldWithHeld UserField = "withheld"
)

type UserFieldOptions

type UserFieldOptions struct {
	Expansions  []Expansion
	TweetFields []TweetField
	UserFields  []UserField
}

UserFieldOptions are the tweet options for the response

type UserFollowLookup

type UserFollowLookup struct {
	Lookups UserLookups
	Meta    *UserFollowMeta
	Errors  []ErrorObj
}

UserFollowLookup contains all of the user following information

type UserFollowMeta

type UserFollowMeta struct {
	ResultCount   int    `json:"result_count"`
	PreviousToken string `json:"previous_token"`
	NextToken     string `json:"next_token"`
}

UserFollowMeta the meta that is returned for the following APIs

type UserFollowOptions

type UserFollowOptions struct {
	Expansions      []Expansion
	TweetFields     []TweetField
	UserFields      []UserField
	MaxResults      int
	PaginationToken string
}

UserFollowOptions are the options that can be passed for the following APIs

type UserLookup

type UserLookup struct {
	User  UserObj
	Tweet *TweetObj
}

UserLookup is a complete user objects

type UserLookups

type UserLookups map[string]UserLookup

UserLookups is a map of user lookups

type UserMetricsObj

type UserMetricsObj struct {
	Followers int `json:"followers_count"`
	Following int `json:"following_count"`
	Tweets    int `json:"tweet_count"`
	Listed    int `json:"listed_count"`
}

UserMetricsObj contains details about activity for this user

type UserObj

type UserObj struct {
	ID              string         `json:"id"`
	Name            string         `json:"name"`
	UserName        string         `json:"username"`
	CreatedAt       string         `json:"created_at"`
	Description     string         `json:"description"`
	Entities        EntitiesObj    `json:"entities"`
	Location        string         `json:"location"`
	PinnedTweetID   string         `json:"pinned_tweet_id"`
	ProfileImageURL string         `json:"profile_image_url"`
	Protected       bool           `json:"protected"`
	PublicMetrics   UserMetricsObj `json:"public_metrics"`
	URL             string         `json:"url"`
	Verified        bool           `json:"verified"`
	WithHeld        WithHeldObj    `json:"withheld"`
}

UserObj contains Twitter user account metadata describing the referenced user

type UserSearchResp

type UserSearchResp struct {
	UserObj []*UserObj `json:"data"`
}

type UserTimeline

type UserTimeline struct {
	Tweets   []TweetObj            `json:"data"`
	Includes *UserTimelineIncludes `json:"includes"`
	Errors   []ErrorObj            `json:"errors"`
	Meta     UserTimelineMeta      `json:"meta"`
}

UserTimeline is the response to the user tweet timeline API

type UserTimelineIncludes

type UserTimelineIncludes struct {
	Medias []MediaObj `json:"media"`
	Users  []UserObj  `json:"users"`
	Tweets []TweetObj `json:"tweets"`
	Places []PlaceObj `json:"places"`
	Polls  string     `json:"polls"`
}

UserTimelineIncludes will contain the optional response objects

type UserTimelineMeta

type UserTimelineMeta struct {
	OldestID      string `json:"oldest_id"`
	NewestID      string `json:"newest_id"`
	ResultCount   int    `json:"result_count"`
	NextToken     string `json:"next_token"`
	PreviousToken string `json:"previous_token"`
}

UserTimelineMeta is the meta data of the response

type UserTimelineOpts

type UserTimelineOpts struct {
	Excludes        []Exclude
	Expansions      []Expansion
	MediaFields     []MediaField
	PlaceFields     []PlaceField
	PollFields      []PollField
	TweetFields     []TweetField
	UserFields      []UserField
	SinceID         string
	UntilID         string
	PaginationToken string
	MaxResults      int
	StartTime       time.Time
	EndTime         time.Time
}

UserTimelineOpts are options in the user tweet timeline

type WithHeldObj

type WithHeldObj struct {
	Copyright    bool     `json:"copyright"`
	CountryCodes []string `json:"country_codes"`
}

WithHeldObj contains withholding details

Jump to

Keyboard shortcuts

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