Documentation
¶
Overview ¶
Package types defines types for the Twitter API v2 object model.
The core types of the object model are Tweet, User, Poll, Media, and Place. Other types are defined for the interior structure of the core objects.
Enumerators for field parameters are generated by the mkenum tool using the field tags on the core types, using the string tags on the fields. When adding, changing, or removing fields on these types, run "go generate" to update the generated code.
Index ¶
- Constants
- type Annotation
- type Attachments
- type ContextAnnotation
- type Domain
- type Entities
- type Entity
- type ErrorDetail
- type Expansions
- type Fields
- type List
- type ListFields
- type Lists
- type Location
- type Media
- type MediaFields
- type Medias
- type Mention
- type MetricSet
- type Metrics
- type Milliseconds
- type Minutes
- type Place
- type PlaceFields
- type Places
- type Poll
- type PollFields
- type PollOption
- type Polls
- type Ref
- type Span
- type Tag
- type Tweet
- type TweetFields
- type Tweets
- type URL
- type User
- type UserEntities
- type UserFields
- type Users
- type Withholding
Constants ¶
const ( Metric_FollowersCount = "followers_count" // public Metric_FollowingCount = "following_count" // public Metric_ImpressionCount = "impression_count" // non-public, organic, promoted Metric_LikeCount = "like_count" // public, organic, promoted Metric_ListedCount = "listed_count" // public Metric_QuoteCount = "quote_count" // public Metric_ReplyCount = "reply_count" // public, organic, promoted Metric_RetweetCount = "retweet_count" // public, organic, promoted Metric_TweetCount = "tweet_count" // public Metric_URLLinkClicks = "url_link_clicks" // non-public, organic, promoted Metric_UserProfileClicks = "user_profile_clicks" // non-public, organic, promoted Metric_ViewCount = "view_count" // public, organic, promoted // Video view quartile metrics. Non-public, organic, promoted. Metric_Playback0Count = "playback_0_count" Metric_Playback25Count = "playback_25_count" Metric_Playback50Count = "playback_50_count" Metric_Playback75Count = "playback_75_count" Metric_Playback100Count = "playback_100_count" )
Constants for the names of various metrics reported in a Metrics map. The comment beside each constant describes its visibility.
See https://developer.twitter.com/en/docs/twitter-api/metrics
const DateFormat = time.RFC3339Nano
DateFormat defines the encoding format for timestamps.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Annotation ¶
type Annotation struct {
Span
Probability float64 `json:"probability"`
Type string `json:"type"`
NormalizedText string `json:"normalized_text"`
}
An Annotation records the location, and type of a programmatic annotation.
type Attachments ¶
Attachments is a map of attachment type keys to string IDs for objects attached to a reply.
type ContextAnnotation ¶
A ContextAnnotation is a collection of domain and/or entity labels, inferred based on the text of a tweet. Context annotations can yield one or many domains.
type Domain ¶
type Domain struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
}
A Domain is a single domain label associated with a tweet.
See https://developer.twitter.com/en/docs/twitter-api/annotations for a table of defined annotation domains.
type Entities ¶
type Entities struct {
Annotations []*Annotation `json:"annotations,omitempty"`
CashTags []*Tag `json:"cashtags,omitempty"`
HashTags []*Tag `json:"hashtags,omitempty"`
Mentions []*Mention `json:"mentions,omitempty"`
URLs []*URL `json:"urls,omitempty"`
}
Entities captures annotations and other embedded entities in a text.
type Entity ¶
An Entity identifies a programmatically-defined entity annotation associated with a particular span of a tweet (see Annotation).
type ErrorDetail ¶
type ErrorDetail struct {
ClientID string `json:"client_id,omitempty"` // e.g., "1011011"
Title string `json:"title"` // e.g., "Not Found Error"
Detail string `json:"detail"` // for human consumption
Parameter string `json:"parameter"` // e.g., "pinned_tweet_id"
Value string `json:"value"` // e.g., "12345"
Reason string `json:"reason,omitempty"` // e.g., "client-not-enrolled"
ResourceType string `json:"resource_type"` // e.g., "tweet"
TypeURL string `json:"type"` // link to problem definition
}
ErrorDetail describes an error condition reported in an otherwise successful reply from the API, such as missing expansion data.
See https://developer.twitter.com/en/support/twitter-api/error-troubleshooting
type Expansions ¶
type Expansions struct {
// Return a user object representing the Tweet’s author.
AuthorID bool `json:"author_id"`
// Return a Tweet object that this Tweet is referencing (either as a
// Retweet, Quoted Tweet, or reply).
ReferencedTweetID bool `json:"referenced_tweets.id"`
// Return a user object representing the Tweet author this requested Tweet
// is a reply of.
InReplyTo bool `json:"in_reply_to_user_id"`
// Return a media object representing the images, videos, GIFs included in
// the Tweet.
MediaKeys bool `json:"attachments.media_keys"`
// Return a poll object containing metadata for the poll included in the Tweet.
PollID bool `json:"attachments.poll_ids"`
// Return a place object containing metadata for the location tagged in the Tweet.
PlaceID bool `json:"geo.place_id"`
// Return a user object for the user mentioned in the Tweet.
MentionUsername bool `json:"entities.mentions.username"`
// Return a user object for the author of the referenced Tweet.
ReferencedAuthorID bool `json:"referenced_tweets.id.author_id"`
// Return a Tweet object representing the Tweet pinned to the top of the
// user’s profile.
PinnedTweetID bool `json:"pinned_tweet_id"`
// Return a user object representing a list's owner.
OwnerID bool `json:"owner_id"`
}
Expansions represents a set of object field expansions.
func (Expansions) Label ¶
func (Expansions) Label() string
Label returns the parameter tag for optional Expansions fields.
func (*Expansions) Set ¶
func (f *Expansions) Set(name string, value bool) bool
Set sets the selected field of f to value, by its parameter name. It reports whether name is a known parameter of f.
func (Expansions) Values ¶
func (f Expansions) Values() []string
Values returns a slice of the selected field names from f.
type Fields ¶
type Fields interface {
// Return the parameter label for this field type.
Label() string
// Return the values selected for this field type.
Values() []string
}
Fields defines a set of optional response fields to request. This interface is satisfied by the generated enumeration types.
type List ¶
type List struct {
ID string `json:"id" twitter:"default"`
Name string `json:"name" twitter:"default"`
CreatedAt *time.Time `json:"created_at,omitempty"`
Description string `json:"description,omitempty"`
Followers int `json:"follower_count,omitempty"`
Members int `json:"member_count,omitempty"`
OwnerID string `json:"owner_id,omitempty"`
Private bool `json:"private,omitempty"`
}
A List is the decoded form of list metadata. The fields marked "default" will always be populated by the API; other fields are filled in based on the parameters in the request.
type ListFields ¶
type ListFields struct {
CreatedAt bool // created_at
Description bool // description
Followers bool // follower_count
Members bool // member_count
OwnerID bool // owner_id
Private bool // private
}
ListFields defines optional List field parameters.
func (ListFields) Label ¶
func (ListFields) Label() string
Label returns the parameter tag for optional List fields.
func (*ListFields) Set ¶
func (f *ListFields) Set(name string, value bool) bool
Set sets the selected field of f to value, by its parameter name. It reports whether name is a known parameter of f.
func (ListFields) Values ¶
func (f ListFields) Values() []string
Values returns a slice of the selected field names from f.
type Location ¶
type Location struct {
PlaceID string `json:"place_id"`
Coordinates json.RawMessage `json:"coordinates"` // as GeoJSON
}
A Location carries the content of a place ("geo"). The payload is encoded as GeoJSON, see https://geojson.org. It is captured here as raw JSON.
type Media ¶
type Media struct {
Key string `json:"media_key" twitter:"default"`
Type string `json:"type" twitter:"default"` // e.g., "video"
URL string `json:"url"`
Duration Milliseconds `json:"duration_ms"`
Height int `json:"height"` // pixels
Width int `json:"width"` // pixels
PreviewImageURL string `json:"preview_image_url"`
Attachments `json:"attachments"`
MetricSet
}
Media refers to any image, GIF, or video attached to a tweet. The fields marked "default" will always be populated by the API; other fields are filled in based on the parameters in the request.
type MediaFields ¶
type MediaFields struct {
Attachments bool // attachments
Duration bool // duration_ms
Height bool // height
NonPublicMetrics bool // non_public_metrics
OrganicMetrics bool // organic_metrics
PreviewImageURL bool // preview_image_url
PromotedMetrics bool // promoted_metrics
PublicMetrics bool // public_metrics
URL bool // url
Width bool // width
}
MediaFields defines optional Media field parameters.
func (MediaFields) Label ¶
func (MediaFields) Label() string
Label returns the parameter tag for optional Media fields.
func (*MediaFields) Set ¶
func (f *MediaFields) Set(name string, value bool) bool
Set sets the selected field of f to value, by its parameter name. It reports whether name is a known parameter of f.
func (MediaFields) Values ¶
func (f MediaFields) Values() []string
Values returns a slice of the selected field names from f.
type MetricSet ¶
type MetricSet struct {
// Metric totals that are available for anyone to access on Twitter, such as
// number of likes and number of retweets.
PublicMetrics Metrics `json:"public_metrics,omitempty"`
// Metrics totals that are not available for anyone to view on Twitter, such
// as number of impressions and video view quartiles.
// Requires OAuth 1.0a User Context authentication.
NonPublicMetrics Metrics `json:"non_public_metrics,omitempty" twitter:"user-context"`
// A grouping of public and non-public metrics attributed to an organic
// context (posted and viewed in a regular manner).
// Requires OAuth 1.0a User Context authentication.
OrganicMetrics Metrics `json:"organic_metrics,omitempty" twitter:"user-context"`
// A grouping of public and non-public metrics attributed to a promoted
// context (posted or viewed as part of an Ads campaign).
// Requires OAuth 1.0a User Context authentication, and that the tweet was
// promoted in an Ad.
//
// Promoted metrics are NOT included in these counts when a Twitter user is
// using their own Ads account to promote another Twitter user's tweets.
//
// Promoted metrics ARE included in these counts when a Twitter user
// promotes their own Tweets in an Ads account for a specific handle, the
// admin for that account may add another Twitter user as an account user so
// this second account user can promote Tweets for the handle.
PromotedMetrics Metrics `json:"promoted_metrics,omitempty" twitter:"user-context"`
}
A MetricSet collects the metric types that can be requested from the API.
type Milliseconds ¶
Milliseconds defines the JSON encoding of a duration in milliseconds.
func (Milliseconds) MarshalJSON ¶
func (m Milliseconds) MarshalJSON() ([]byte, error)
MarshalJSON encodes m as a JSON integer number of milliseconds.
func (*Milliseconds) UnmarshalJSON ¶
func (m *Milliseconds) UnmarshalJSON(bits []byte) error
UnmarshalJSON decodes d from a JSON integer number of milliseconds.
type Minutes ¶
Minutes defines the JSON encoding of a duration in minutes.
func (Minutes) MarshalJSON ¶
MarshalJSON encodes d as a JSON integer number of minutes. Time intervals smaller than a minute are rounded toward zero.
func (*Minutes) UnmarshalJSON ¶
UnmarshalJSON decodes d from a JSON integer number of minutes.
type Place ¶
type Place struct {
ID string `json:"id" twitter:"default"`
FullName string `json:"full_name" twitter:"default"` // e.g., "Manhattan, New York"
Name string `json:"name"` // short name, e.g., "Manhattan"
Type string `json:"place_type"` // e.g., "city"
ContainedIn []string `json:"contained_within"`
CountryName string `json:"country"` // e.g., "United States"
CountryCode string `json:"country_code"` // e.g., "US"; https://www.iso.org/obp/ui/#search
Location json.RawMessage `json:"geo"` // in GeoJSON; https://geojson.org/
Attachments `json:"attachments"`
}
A Place describes a location mentioned in a tweet or user description. The fields marked "default" will always be populated by the API; other fields are filled in based on the parameters in the request.
type PlaceFields ¶
type PlaceFields struct {
Attachments bool // attachments
ContainedIn bool // contained_within
CountryName bool // country
CountryCode bool // country_code
Location bool // geo
Name bool // name
Type bool // place_type
}
PlaceFields defines optional Place field parameters.
func (PlaceFields) Label ¶
func (PlaceFields) Label() string
Label returns the parameter tag for optional Place fields.
func (*PlaceFields) Set ¶
func (f *PlaceFields) Set(name string, value bool) bool
Set sets the selected field of f to value, by its parameter name. It reports whether name is a known parameter of f.
func (PlaceFields) Values ¶
func (f PlaceFields) Values() []string
Values returns a slice of the selected field names from f.
type Poll ¶
type Poll struct {
ID string `json:"id" twitter:"default"`
Options []*PollOption `json:"options" twitter:"default"`
Duration Minutes `json:"duration_minutes"`
EndTime *time.Time `json:"end_datetime"`
VotingStatus string `json:"voting_status"` // e.g., "closed"
Attachments `json:"attachments"`
}
A Poll is the encoded description of a Twitter poll. The fields marked "default" will always be populated by the API; other fields are filled in based on the parameters in the request.
type PollFields ¶
type PollFields struct {
Attachments bool // attachments
Duration bool // duration_minutes
EndTime bool // end_datetime
VotingStatus bool // voting_status
}
PollFields defines optional Poll field parameters.
func (PollFields) Label ¶
func (PollFields) Label() string
Label returns the parameter tag for optional Poll fields.
func (*PollFields) Set ¶
func (f *PollFields) Set(name string, value bool) bool
Set sets the selected field of f to value, by its parameter name. It reports whether name is a known parameter of f.
func (PollFields) Values ¶
func (f PollFields) Values() []string
Values returns a slice of the selected field names from f.
type PollOption ¶
type PollOption struct {
Position int `json:"position"`
Label string `json:"label"`
Votes int `json:"votes"`
}
A PollOption is a single choice item in a poll.
type Tweet ¶
type Tweet struct {
ID string `json:"id" twitter:"default"`
Text string `json:"text" twitter:"default"`
AuthorID string `json:"author_id,omitempty"`
ConversationID string `json:"conversation_id,omitempty"`
CreatedAt *time.Time `json:"created_at,omitempty"`
Entities *Entities `json:"entities,omitempty"`
InReplyTo string `json:"in_reply_to_user_id,omitempty"`
Language string `json:"lang,omitempty"` // https://tools.ietf.org/html/bcp47
Location *Location `json:"geo,omitempty"`
Sensitive bool `json:"possibly_sensitive,omitempty"`
Referenced []*Ref `json:"referenced_tweets,omitempty"`
Source string `json:"source,omitempty"` // e.g., "Twitter Web App"
ContextAnnotations []*ContextAnnotation `json:"context_annotations,omitempty"`
Withheld *Withholding `json:"withheld,omitempty"`
Attachments `json:"attachments,omitempty"`
MetricSet
}
A Tweet is the decoded form of a single tweet. The fields marked "default" will always be populated by the API; other fields are filled in based on the parameters in the request.
type TweetFields ¶
type TweetFields struct {
Attachments bool // attachments
AuthorID bool // author_id
ContextAnnotations bool // context_annotations
ConversationID bool // conversation_id
CreatedAt bool // created_at
Entities bool // entities
Location bool // geo
InReplyTo bool // in_reply_to_user_id
Language bool // lang
NonPublicMetrics bool // non_public_metrics
OrganicMetrics bool // organic_metrics
Sensitive bool // possibly_sensitive
PromotedMetrics bool // promoted_metrics
PublicMetrics bool // public_metrics
Referenced bool // referenced_tweets
Source bool // source
Withheld bool // withheld
}
TweetFields defines optional Tweet field parameters.
func (TweetFields) Label ¶
func (TweetFields) Label() string
Label returns the parameter tag for optional Tweet fields.
func (*TweetFields) Set ¶
func (f *TweetFields) Set(name string, value bool) bool
Set sets the selected field of f to value, by its parameter name. It reports whether name is a known parameter of f.
func (TweetFields) Values ¶
func (f TweetFields) Values() []string
Values returns a slice of the selected field names from f.
type URL ¶
type URL struct {
Span
URL string `json:"url"`
Expanded string `json:"expanded_url"`
Display string `json:"display_url"`
Unwound string `json:"unwound_url,omitempty"`
HTTPStatus int `json:"status,omitempty"` // e.g., 200
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
}
A URL denotes a span of text encoding a URL.
type User ¶
type User struct {
ID string `json:"id" twitter:"default"`
Name string `json:"name" twitter:"default"` // e.g., "User McJones"
Username string `json:"username" twitter:"default"` // e.g., "mcjonesey"
CreatedAt *time.Time `json:"created_at,omitempty"`
Description string `json:"description,omitempty"` // profile bio
ProfileURL string `json:"url,omitempty"`
Entities *UserEntities `json:"entities,omitempty"`
FuzzyLocation string `json:"location,omitempty"` // human-readable
PinnedTweetID string `json:"pinned_tweet_id,omitempty"`
ProfileImageURL string `json:"profile_image_url,omitempty"`
Protected bool `json:"protected,omitempty"`
Verified bool `json:"verified,omitempty"`
PublicMetrics Metrics `json:"public_metrics,omitempty"`
Withheld *Withholding `json:"withheld,omitempty"`
}
A User contains Twitter user account metadata describing a Twitter user. The fields marked "default" will always be populated by the API; other fields are filled in based on the parameters in the request.
type UserEntities ¶
type UserEntities struct {
URL Entities `json:"url,omitempty"`
Description Entities `json:"description,omitempty"`
}
UserEntities describe entities found in a user's profile.
type UserFields ¶
type UserFields struct {
CreatedAt bool // created_at
Description bool // description
Entities bool // entities
FuzzyLocation bool // location
PinnedTweetID bool // pinned_tweet_id
ProfileImageURL bool // profile_image_url
Protected bool // protected
PublicMetrics bool // public_metrics
ProfileURL bool // url
Verified bool // verified
Withheld bool // withheld
}
UserFields defines optional User field parameters.
func (UserFields) Label ¶
func (UserFields) Label() string
Label returns the parameter tag for optional User fields.
func (*UserFields) Set ¶
func (f *UserFields) Set(name string, value bool) bool
Set sets the selected field of f to value, by its parameter name. It reports whether name is a known parameter of f.
func (UserFields) Values ¶
func (f UserFields) Values() []string
Values returns a slice of the selected field names from f.
type Users ¶
type Users []*User
Users is a searchable slice of User values.
func (Users) FindByUsername ¶
FindByUsername returns the first User in us whose Username matches, or nil.
type Withholding ¶
type Withholding struct {
Copyright bool `json:"copyright"`
CountryCodes []string `json:"country_codes"`
}
Withholding describes content restrictions.