twitter

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2021 License: MIT Imports: 9 Imported by: 0

README

go-twitter v2

It seems like every v1 is just a prototype.

One of my co-workers said that when we were working on a project, released the first version and then realizing that there were many improvements that needed to be done. That seems to ring true, and this library is not exception. When looking at the improvements that needed to be done, unfortunately these improvements will introduce breaking changes. This version will focus on giving the caller more information from the callouts to allow for better response handling. Another factor is to think about improvements, but first delivering the information first then providing more funcitonality second.

There will be beta releases throughout this process and if there are any new functionality requested, it will be discussed to try and get it into this version. Version 1 will still be maintained as I believe that version 2 will need to be mature before the pervious version is even considered to be sunset.

This project will track the process of this initial version.

go get -u github.com/g8rswimmer/go-twitter/v2

Changes

The following are changes between v1 and v2 of the library.

  • One structure for all endpoint callouts. In v1 there were two structures, Tweet and User, to preform callouts. This required management of two structures and knowledge which structure contained the desired method callouts. At the time, the grouping looked logical. However with the addtion of the timeline endpoints, it makes more sense to have a single struture Client to handle all of the callouts. If the user would like to separate the functionality, interfaces can be used to achieve this.
  • Endpoint methods will return the entire response. One of the major drawbacks of v1 was the object returned was not the entire response sent by the callout. For example, the errors object in the response is included in v1 response which does not allow the caller to properly handle partial errors. In v2, the first focus is to return the response from twitter to allow the caller to use it as they see fit. However, it does not mean that methods can not be added to the response object to provide groupings, etc.

Features

Here are the current twitter v2 API features supported:

Examples

Much like v1, there is an _example directory to demostrate library usage. Refer to the readme for more information.

Simple Usage

import (
	"encoding/json"
	"log"
	"flag"
	"fmt"
	"net/http"
	"context"
	"strings"

	twitter "github.com/g8rswimmer/go-twitter/v2"
)

type authorize struct {
	Token string
}

func (a authorize) Add(req *http.Request) {
	req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", a.Token))
}

/**
	In order to run, the user will need to provide the bearer token and the list of ids.
**/
func main() {
	token := flag.String("token", "", "twitter API token")
	ids := flag.String("ids", "", "twitter ids")
	flag.Parse()

	client := &twitter.Client{
		Authorizer: authorize{
			Token: *token,
		},
		Client: http.DefaultClient,
		Host:   "https://api.twitter.com",
	}
	opts := twitter.TweetLookupOpts{
		Expansions:  []twitter.Expansion{twitter.ExpansionEntitiesMentionsUserName, twitter.ExpansionAuthorID},
		TweetFields: []twitter.TweetField{twitter.TweetFieldCreatedAt, twitter.TweetFieldConversationID, twitter.TweetFieldAttachments},
	}

	fmt.Println("Callout to tweet lookup callout")

	tweetDictionary, err := client.TweetLookup(context.Background(), strings.Split(*ids, ","), opts)
	if err != nil {
		log.Panicf("tweet lookup error: %v", err)
	}

	enc, err := json.MarshalIndent(tweetDictionary, "", "    ")
	if err != nil {
		log.Panic(err)
	}
	fmt.Println(string(enc))
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrParameter = errors.New("twitter input parameter error")

ErrParameter will indicate that the error is from an invalid input parameter

Functions

This section is empty.

Types

type Authorizer

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

Authorizer will add the authorization to the HTTP request

type Client

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

Client is used to make twitter v2 API callouts.

func (*Client) TweetLookup

func (c *Client) TweetLookup(ctx context.Context, ids []string, opts TweetLookupOpts) (*TweetLookupResponse, error)

TweetLookup returns information about a tweet or group of tweets specified by a group of tweet ids.

func (*Client) TweetRecentSearch added in v1.1.3

func (c *Client) TweetRecentSearch(ctx context.Context, query string, opts TweetRecentSearchOpts) (*TweetRecentSearchResponse, error)

TweetRecentSearch will return a recent search based of a query

func (*Client) UserFollowersLookup added in v1.1.3

func (c *Client) UserFollowersLookup(ctx context.Context, id string, opts UserFollowersLookupOpts) (*UserFollowersLookupResponse, error)

UserFollowersLookup will return a user's followers

func (*Client) UserFollowingLookup added in v1.1.3

func (c *Client) UserFollowingLookup(ctx context.Context, id string, opts UserFollowingLookupOpts) (*UserFollowingLookupResponse, error)

UserFollowingLookup will return a user's following users

func (*Client) UserLookup added in v1.1.2

func (c *Client) UserLookup(ctx context.Context, ids []string, opts UserLookupOpts) (*UserLookupResponse, error)

UserLookup returns information about an user or group of users specified by a group of user ids.

func (*Client) UserNameLookup added in v1.1.2

func (c *Client) UserNameLookup(ctx context.Context, usernames []string, opts UserLookupOpts) (*UserLookupResponse, error)

UserNameLookup returns information about an user or group of users specified by a group of usernames.

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 Error

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

Error is part of the HTTP response error

type ErrorObj

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

ErrorObj is part of the partial errors in the response

type ErrorResponse

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

ErrorResponse is returned by a non-success callout

func (*ErrorResponse) Error

func (e *ErrorResponse) Error() string

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 added in v1.1.3

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 added in v1.1.3

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,omitempty"`
	NonPublicMetrics *MediaMetricsObj `json:"non_public_metrics,omitempty"`
	OrganicMetrics   *MediaMetricsObj `json:"organic_metrics,omitempty"`
	PreviewImageURL  string           `json:"preview_image_url,omitempty"`
	PromotedMetrics  *MediaMetricsObj `json:"promoted_metrics,omitempty"`
	PublicMetrics    *MediaMetricsObj `json:"public_metrics,omitempty"`
	Width            int              `json:"width,omitempty"`
}

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

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,omitempty"`
	ID              string       `json:"id"`
	ContainedWithin []string     `json:"contained_within,omitempty"`
	Country         string       `json:"country,omitempty"`
	CountryCode     string       `json:"country_code,omitempty"`
	Geo             *PlaceGeoObj `json:"geo,omitempty"`
	Name            string       `json:"name"`
	PlaceType       string       `json:"place_type,omitempty"`
}

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,omitempty"`
	DurationMinutes int              `json:"duration_minutes,omitempty"`
	EndDateTime     string           `json:"end_datetime,omitempty"`
	VotingStatus    string           `json:"voting_status,omitempty"`
}

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 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 TweetDictionary

type TweetDictionary struct {
	Tweet            TweetObj
	Author           *UserObj
	InReplyUser      *UserObj
	Place            *PlaceObj
	AttachmentPolls  []*PollObj
	AttachmentMedia  []*MediaObj
	Mentions         []*TweetMention
	ReferencedTweets []*TweetReference
}

TweetDictionary is a struct of a tweet and all of the reference objects

func CreateTweetDictionary

func CreateTweetDictionary(tweet TweetObj, includes *TweetRawIncludes) *TweetDictionary

CreateTweetDictionary will create a dictionary from a tweet and the includes

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"
	// 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 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 TweetLookupOpts

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

TweetLookupOpts are the optional paramters that can be passed to the lookup callout

type TweetLookupResponse

type TweetLookupResponse struct {
	Raw *TweetRaw
}

TweetLookupResponse contains all of the information from a tweet lookup callout

type TweetMention

type TweetMention struct {
	Mention *EntityMentionObj
	User    *UserObj
}

TweetMention is the mention and the user associated with it

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,omitempty"`
	AuthorID           string                       `json:"author_id,omitempty"`
	ContextAnnotations []*TweetContextAnnotationObj `json:"context_annotations,omitempty"`
	ConversationID     string                       `json:"conversation_id,omitempty"`
	CreatedAt          string                       `json:"created_at,omitempty"`
	Entities           *EntitiesObj                 `json:"entities,omitempty"`
	Geo                *TweetGeoObj                 `json:"geo,omitempty"`
	InReplyToUserID    string                       `json:"in_reply_to_user_id,omitempty"`
	Language           string                       `json:"lang,omitempty"`
	NonPublicMetrics   *TweetMetricsObj             `json:"non_public_metrics,omitempty"`
	OrganicMetrics     *TweetMetricsObj             `json:"organic_metrics,omitempty"`
	PossibySensitive   bool                         `json:"possiby_sensitive,omitempty"`
	PromotedMetrics    *TweetMetricsObj             `json:"promoted_metrics,omitempty"`
	PublicMetrics      *TweetMetricsObj             `json:"public_metrics,omitempty"`
	ReferencedTweets   []*TweetReferencedTweetObj   `json:"referenced_tweets,omitempty"`
	Source             string                       `json:"source,omitempty"`
	WithHeld           *WithHeldObj                 `json:"withheld,omitempty"`
}

TweetObj is the primary object on the tweets endpoints

type TweetRaw

type TweetRaw struct {
	Tweets   []*TweetObj       `json:"data"`
	Includes *TweetRawIncludes `json:"includes,omitempty"`
	Errors   []*ErrorObj       `json:"errors,omitempty"`
	// contains filtered or unexported fields
}

TweetRaw is the raw response from the tweet lookup endpoint

func (*TweetRaw) TweetDictionaries

func (t *TweetRaw) TweetDictionaries() map[string]*TweetDictionary

TweetDictionaries create a map of tweet dictionaries from the raw tweet response

type TweetRawIncludes

type TweetRawIncludes struct {
	Tweets []*TweetObj `json:"tweets,omitempty"`
	Users  []*UserObj  `json:"users,omitempty"`
	Places []*PlaceObj `json:"places,omitempty"`
	Media  []*MediaObj `json:"media,omitempty"`
	Polls  []*PollObj  `json:"polls,omitempty"`
	// contains filtered or unexported fields
}

TweetRawIncludes contains any additional information from the tweet callout

func (*TweetRawIncludes) MediaByKeys

func (t *TweetRawIncludes) MediaByKeys() map[string]*MediaObj

MediaByKeys will return a map of media keys to object

func (*TweetRawIncludes) PlacesByID

func (t *TweetRawIncludes) PlacesByID() map[string]*PlaceObj

PlacesByID will return a map of place ids to object

func (*TweetRawIncludes) PollsByID

func (t *TweetRawIncludes) PollsByID() map[string]*PollObj

PollsByID will return a map of poll ids to object

func (*TweetRawIncludes) TweetsByID

func (t *TweetRawIncludes) TweetsByID() map[string]*TweetObj

TweetsByID will return a map of tweet ids to object

func (*TweetRawIncludes) UsersByID

func (t *TweetRawIncludes) UsersByID() map[string]*UserObj

UsersByID will return a map of user ids to object

func (*TweetRawIncludes) UsersByUserName

func (t *TweetRawIncludes) UsersByUserName() map[string]*UserObj

UsersByUserName will return a map of user names to object

type TweetRecentSearchMeta added in v1.1.3

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

TweetRecentSearchMeta contains the recent search information

type TweetRecentSearchOpts added in v1.1.3

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

TweetRecentSearchOpts are the optional parameters for the recent seach API

type TweetRecentSearchResponse added in v1.1.3

type TweetRecentSearchResponse struct {
	Raw  *TweetRaw
	Meta *TweetRecentSearchMeta `json:"meta"`
}

TweetRecentSearchResponse contains all of the information from a tweet recent search

type TweetReference

type TweetReference struct {
	Reference       *TweetReferencedTweetObj
	TweetDictionary *TweetDictionary
}

TweetReference is the tweet referenced and it's dictionary

type TweetReferencedTweetObj

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

TweetReferencedTweetObj is a Tweet this Tweet refers to

type UserDictionary added in v1.1.2

type UserDictionary struct {
	User        UserObj
	PinnedTweet *TweetObj
}

UserDictionary is a struct of an user and all of the reference objects

func CreateUserDictionary added in v1.1.2

func CreateUserDictionary(user UserObj, includes *UserRawIncludes) *UserDictionary

CreateUserDictionary will create a dictionary from a user and the includes

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 UserFollowersLookupOpts added in v1.1.3

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

UserFollowersLookupOpts are the options for the user followers API

type UserFollowersLookupResponse added in v1.1.3

type UserFollowersLookupResponse struct {
	Raw  *UserRaw
	Meta *UserFollowershMeta `json:"meta"`
}

UserFollowersLookupResponse is the response for the user followers API

type UserFollowershMeta added in v1.1.3

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

UserFollowershMeta is the meta data returned by the user followers API

type UserFollowingLookupOpts added in v1.1.3

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

UserFollowingLookupOpts are the options for the user following API

type UserFollowingLookupResponse added in v1.1.3

type UserFollowingLookupResponse struct {
	Raw  *UserRaw
	Meta *UserFollowinghMeta `json:"meta"`
}

UserFollowingLookupResponse is the response for the user following API

type UserFollowinghMeta added in v1.1.3

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

UserFollowinghMeta is the meta data returned by the user following API

type UserLookupOpts added in v1.1.2

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

UserLookupOpts are the optional paramters that can be passed to the lookup callout

type UserLookupResponse added in v1.1.2

type UserLookupResponse struct {
	Raw *UserRaw
}

UserLookupResponse contains all of the information from an user lookup callout

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,omitempty"`
	Description     string          `json:"description,omitempty"`
	Entities        *EntitiesObj    `json:"entities,omitempty"`
	Location        string          `json:"location,omitempty"`
	PinnedTweetID   string          `json:"pinned_tweet_id,omitempty"`
	ProfileImageURL string          `json:"profile_image_url,omitempty"`
	Protected       bool            `json:"protected,omitempty"`
	PublicMetrics   *UserMetricsObj `json:"public_metrics,omitempty"`
	URL             string          `json:"url,omitempty"`
	Verified        bool            `json:"verified,omitempty"`
	WithHeld        *WithHeldObj    `json:"withheld,omitempty"`
}

UserObj contains Twitter user account metadata describing the referenced user

type UserRaw added in v1.1.2

type UserRaw struct {
	Users    []*UserObj       `json:"data"`
	Includes *UserRawIncludes `json:"includes,omitempty"`
	Errors   []*ErrorObj      `json:"errors,omitempty"`
	// contains filtered or unexported fields
}

UserRaw is the raw response from the user lookup endpoint

func (*UserRaw) UserDictionaries added in v1.1.2

func (u *UserRaw) UserDictionaries() map[string]*UserDictionary

UserDictionaries create a map of user dictionaries from the raw user response

type UserRawIncludes added in v1.1.2

type UserRawIncludes struct {
	Tweets []*TweetObj `json:"tweets,omitempty"`
	// contains filtered or unexported fields
}

UserRawIncludes contains any additional information from the user callout

func (*UserRawIncludes) TweetsByID added in v1.1.2

func (u *UserRawIncludes) TweetsByID() map[string]*TweetObj

TweetsByID will return a map of tweet ids to object

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