twigo

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2022 License: MIT Imports: 11 Imported by: 1

README

twigo (Golang Twitter Library)

twigo logo

Twigo is a fast and easy to use twitter API library help you write best twitter bots.

Currently we only support twitter api v2, but version 1.1 will be added soon.

Caution! we are still in Beta phase.

installation

go get github.com/arshamalh/twigo

How to use

Easily make a new client!

package main

import "github.com/arshamalh/twigo"

twigo.NewClient((&twigo.Config{
  ConsumerKey:    "ConsumerKey",
  ConsumerSecret: "ConsumerSecret",
  AccessToken:    "AccessToken",
  AccessSecret:   "AccessTokenSecret",
  // Both of "bearer token" or "four other keys (ConsumerKey, ...)" is not mandatory.
  // We'll find bearer token automatically if it's not specified.
  // Also, you can use twigo.utils.BearerFinder() function.
  BearerToken:    "BearerToken",
}))

And use any function you need, for example, get a tweet like this:

response, _ := client.GetTweet(tweet_id, nil)
fmt.Printf("%#v\n", response)
tweet := response.Data

Making a tweet, as easy as below:

client.CreateTweet("This is a test tweet", nil)

Retweeting and Liking a tweet:

client.Retweet("1516784368601153548")
client.Like("1431751228145426438")

Or Maybe deleting your like and retweet:

client.UnRetweet("1516784368601153548")
client.Unlike("1516784368601153548")

Simple, right?

Rate limits

How many actions can we do?

You can simpy read RateLimits attribute on the Response!

  RateLimits:{
    Limit:75 // An static number depending on the endpoint that you are calling or your authentication method.
    Remaining:74 // An dynamic method that decreases after each call, and will reset every once in a while.
    ResetTimestamp:1650553033 // Reset (charge up) remaining calls in this timestamp.
  }
More examples:

Passing some extra fields and params:

fields := twigo.Map{"tweet.fields": []string{"author_id", "created_at", "public_metrics"}}
response, _ := client.GetTweet(tweet_id, fields)
fmt.Printf("%#v\n", response)
tweet := response.Data

If the tweet doesn't exist or it's from a suspended account, twigo will return an empty struct instead, You should get tweet.ID and see if it's a "" or not.

&twigo.TweetResponse{
  Data: twigo.Tweet{
    ID:"", 
    Text:"", 
    PublicMetrics:map[string]int(nil)
    // Other fields
  }, 
  Meta: twigo.MetaEntity{
    ResultCount:0, 
    NextToken:""
    // Other fields
  }, 
  RateLimits: twigo.RateLimits{
    Limit:300, 
    Remaining:294, 
    ResetTimestamp:1651585436
  }
}

You can get Liking users: (users who liked a tweet)

response, err := client.GetLikingUsers(
  "1431751228145426438", 
  twigo.Map{
    "max_results": 5,
  })

if err != nil {
  fmt.Println(err)
}

fmt.Printf("%+v\n", response)

And result will be a Go struct like this:

{
  Data:[
    {
      ID:1506623384850948096 
      Name:Rhea Baker 
      Username:RheaBak16183941
      Verified:false
    } {
      ID:1506621280098869252 
      Name:Janice Lane 
      Username:JaniceL44359093
      Verified:false
    }
    // And more...
  ] 
  Includes: // Some structs, read more on docs...
  Errors:[] 
  Meta:{
    ResultCount:5 
    NextToken:7140dibdnow9c7btw480y5xgmlpwtbsh4fyqnqmwz9k4w
    // And more...
  }
  RateLimits:{
    Limit:75
    Remaining:74
    ResetTimestamp:1650553033
  }
}

You can get some users by their username or by their IDs:

response, err := client.GetUsersByUsernames(
  []string{"arshamalh", "elonmusk", "someone_else"}, 
  nil, // There is no param in this example.
)

Return all tweets a user have written in the last 30 minutes.

start_time := time.Now().UTC().Add(-30 * time.Minute)
params := twigo.Map{"max_results": 5, "start_time": start_time}
user_tweets, _ := bot.GetUserTweets(user_id, params)
if len(user_tweets.Data) != 0 {
  fmt.Printf("<<Some tweets found>>")
  for _, tweet := range user_tweets.Data {
		fmt.Printf("%#v\n", tweet)
	}
}
How to paginate over results?

if your method is paginatable, you can paginate using NextPage method attached to the response, like this:

response, _ := client.GetUserTweets("1216345203453452289", nil)
for {
  fmt.Printf("%#v\n", response)
  response, err = response.NextPage()  // Here the magic happens! NextPage method attached to response

  if err != nil {  // Break the loop whenever there is no more pages.
    fmt.Println(err)
    break
  }
}

A little bit more complex example:

response, err := client.GetUserTweets("1216345203453452289", nil)

if err != nil {  // Is there any response at all?
  fmt.Println(err)
} else {
  page_number := 1  // To keep track of page number.
  for {
    fmt.Printf("Page %d: %#v\n", page_number, response)
    response, err = response.NextPage()

    if err != nil {
      fmt.Println(err)
      break
    }

    // If rate limits exceeds, wait until it charges again, 
    // it's not a good approach, because all of your app will sleep, 
    // it's highly recommended to do it in a goroutine instead.
    if response.RateLimits.Remaining == 0 {
      fmt.Println("Rate limit reached")
      sleeping_duration := time.Until(time.Unix(response.RateLimits.ResetTimestamp, 0))
      time.Sleep(sleeping_duration)
		}
    page_number++
  }
}

Contribution

Feel free to open an issue, contribute and contact us!

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultOAuthes = map[string]OAuthType{
	"": OAuth_Default,
}

TODO: Should be completed, for example, Search tweets and Search spaces or muting have OAuth 1 as default, but others, have version 2 as default

Functions

This section is empty.

Types

type BlockResponse

type BlockResponse struct {
	Data struct {
		Blocking bool `json:"blocking"`
	}
	Includes   IncludesEntity
	Errors     []ErrorEntity
	Meta       MetaEntity
	RateLimits RateLimits
}

func (*BlockResponse) Parse

func (r *BlockResponse) Parse(raw_response *http.Response) (*BlockResponse, error)

type BookmarkResponse

type BookmarkResponse struct {
	Data struct {
		Bookmarked bool `json:"bookmarked"`
	}
	Includes   IncludesEntity
	Errors     []ErrorEntity
	Meta       MetaEntity
	RateLimits RateLimits
}

func (*BookmarkResponse) Parse

func (r *BookmarkResponse) Parse(raw_response *http.Response) (*BookmarkResponse, error)

type BookmarkedTweetsResponse

type BookmarkedTweetsResponse struct {
	Data       []entities.Tweet
	Includes   IncludesEntity
	Errors     []ErrorEntity
	Meta       MetaEntity
	RateLimits RateLimits
	CallerData CallerData
	Caller     func(Map) (*BookmarkedTweetsResponse, error)
}

func (*BookmarkedTweetsResponse) NextPage

func (*BookmarkedTweetsResponse) Parse

type CallerData

type CallerData struct {
	ID     string
	Params Map
}

type Client

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

func NewBearerOnlyClient

func NewBearerOnlyClient(bearerToken string) (*Client, error)

func NewClient

func NewClient(config *Config) (*Client, error)

func (*Client) AddListMemeber

func (c *Client) AddListMemeber(list_id, user_id string) (*ListMemberResponse, error)

Enables the authenticated user to add a member to a List they own.

https://developer.twitter.com/en/docs/twitter-api/lists/list-members/api-reference/post-lists-id-members

func (*Client) Block

func (c *Client) Block(target_user_id string) (*BlockResponse, error)

** Blocks ** //

func (*Client) BookmarkTweet

func (c *Client) BookmarkTweet(tweet_id string) (*BookmarkResponse, error)

Causes the authenticating user to Bookmark the target Tweet provided in the request body.

https://developer.twitter.com/en/docs/twitter-api/tweets/bookmarks/api-reference/post-users-id-bookmarks

func (*Client) CreateComplianceJob

func (c *Client) CreateComplianceJob(job_type, name, resumable string) (*ComplianceJobResponse, error)

Creates a new compliance job for Tweet IDs or user IDs.

A compliance job will contain an ID and a destination URL. The destination URL represents the location that contains the list of IDs consumed by your app.

You can run one batch job at a time.

https://developer.twitter.com/en/docs/twitter-api/compliance/batch-compliance/api-reference/post-compliance-jobs

func (*Client) CreateList

func (c *Client) CreateList(name string, description string, private bool, params Map) (*ListResponse, error)

Enables the authenticated user to create a List.

https://developer.twitter.com/en/docs/twitter-api/lists/manage-lists/api-reference/post-lists

func (*Client) CreateTweet

func (c *Client) CreateTweet(text string, params Map) (*TweetResponse, error)

Creates a Tweet on behalf of an authenticated user

Parameters

text: Text of the Tweet being created. this field is required if media.media_ids is not present, otherwise pass empty string.

params: A map of parameters. you can pass some extra parameters, such as:

"direct_message_deep_link", "for_super_followers_only", "media", "geo", "poll", "reply", "reply_settings", "quote_tweet_id",

Some of these parameters are a little special and should be passed like this:

media := map[string][]string{
	"media_ids": []string{}
	"tagged_user_ids": []string{}
}
poll := twigo.Map{
	"options": map[string]string{},
	"duration_minutes": int value,
}
reply := twigo.Map{
	"in_reply_to_tweet_id": "",
	"exclude_reply_user_ids": []string{},
}
geo := map[string]string{"place_id": value}
params := twigo.Map{
	"text": text
	"media": media,
	"geo": geo,
	"poll": poll,
	"reply": reply,
}

Reference

https://developer.twitter.com/en/docs/twitter-api/tweets/manage-tweets/api-reference/post-tweets

func (*Client) DeleteList

func (c *Client) DeleteList(list_id string) (*DeleteResponse, error)

Enables the authenticated user to delete a List that they own.

https://developer.twitter.com/en/docs/twitter-api/lists/manage-lists/api-reference/delete-lists-id

func (*Client) DeleteTweet

func (c *Client) DeleteTweet(tweet_id string) (*DeleteResponse, error)

Allows an authenticated user ID to delete a Tweet

Parameters

tweet_id: The Tweet ID you are deleting.

References

https://developer.twitter.com/en/docs/twitter-api/tweets/manage-tweets/api-reference/delete-tweets-id

func (*Client) FollowList

func (c *Client) FollowList(list_id string) (*FollowResponse, error)

Enables the authenticated user to follow a List.

https://developer.twitter.com/en/docs/twitter-api/lists/list-follows/api-reference/post-users-id-followed-lists

func (*Client) FollowUser

func (c *Client) FollowUser(target_user_id string, params Map) (*FollowResponse, error)

Allows a user ID to follow another user.

If the target user does not have public Tweets, this endpoint will send a follow request.

The request succeeds with no action when the authenticated user sends a request to a user they're already following, or if they're sending a follower request to a user that does not have public Tweets.

https://developer.twitter.com/en/docs/twitter-api/users/follows/api-reference/post-users-source_user_id-following

func (*Client) GetAllTweetsCount

func (c *Client) GetAllTweetsCount(query string, params Map) (*TweetsCountResponse, error)

This endpoint is only available to those users who have been approved for the `Academic Research product track`_.

The full-archive search endpoint returns the complete history of public Tweets matching a search query; since the first Tweet was created March 26, 2006.

https://developer.twitter.com/en/docs/twitter-api/tweets/counts/api-reference/get-tweets-counts-all

func (*Client) GetBlocked

func (c *Client) GetBlocked(params Map) (*UsersResponse, error)

Returns a list of users who are blocked by the authenticating user.

https://developer.twitter.com/en/docs/twitter-api/users/blocks/api-reference/get-users-blocking

func (*Client) GetBookmarkedTweets

func (c *Client) GetBookmarkedTweets(params Map) (*BookmarkedTweetsResponse, error)

Allows you to get an authenticated user's 800 most recent bookmarked Tweets.

https://developer.twitter.com/en/docs/twitter-api/tweets/bookmarks/api-reference/get-users-id-bookmarks

func (*Client) GetComplianceJobs

func (c *Client) GetComplianceJobs(job_type string, params Map) (*ComplianceJobsResponse, error)

Returns a list of recent compliance jobs.

https://developer.twitter.com/en/docs/twitter-api/compliance/batch-compliance/api-reference/get-compliance-jobs

func (*Client) GetFollowedLists

func (c *Client) GetFollowedLists(user_id string, params Map) (*ListsResponse, error)

Returns all Lists a specified user follows.

https://developer.twitter.com/en/docs/twitter-api/lists/list-follows/api-reference/get-users-id-followed_lists

func (*Client) GetLikedTweets

func (c *Client) GetLikedTweets(user_id string, params Map) (*TweetsResponse, error)

Allows you to get information about a user’s liked Tweets.

The Tweets returned by this endpoint count towards the Project-level `Tweet cap`.

Parameters

tweet_id: User ID of the user to request liked Tweets for.

params (keys):

"expansions", "media.fields", "place.fields",
"poll.fields", "tweet.fields", "user.fields",
"max_results"

References

https://developer.twitter.com/en/docs/twitter-api/tweets/likes/api-reference/get-users-id-liked_tweets

func (*Client) GetLikingUsers

func (c *Client) GetLikingUsers(tweet_id string, params Map) (*UsersResponse, error)

Allows you to get information about a Tweet’s liking users.

Parameters

tweet_id: Tweet ID of the Tweet to request liking users of.

params (keys):

"expansions", "media.fields", "place.fields",
"poll.fields", "tweet.fields", "user.fields",
"max_results"

References

https://developer.twitter.com/en/docs/twitter-api/tweets/likes/api-reference/get-tweets-id-liking_users

func (*Client) GetList

func (c *Client) GetList(list_id string, params Map) (*ListResponse, error)

Returns the details of a specified List.

https://developer.twitter.com/en/docs/twitter-api/lists/list-lookup/api-reference/get-lists-id

func (*Client) GetListFollowers

func (c *Client) GetListFollowers(list_id string, params Map) (*UsersResponse, error)

Returns a list of users who are followers of the specified List.

https://developer.twitter.com/en/docs/twitter-api/lists/list-follows/api-reference/get-lists-id-followers

func (*Client) GetListMembers

func (c *Client) GetListMembers(list_id string, params Map) (*UsersResponse, error)

Returns a list of users who are members of the specified List.

https://developer.twitter.com/en/docs/twitter-api/lists/list-members/api-reference/get-lists-id-members

func (*Client) GetListMemberships

func (c *Client) GetListMemberships(user_id string, params Map) (*ListsResponse, error)

Returns all Lists a specified user is a member of.

https://developer.twitter.com/en/docs/twitter-api/lists/list-members/api-reference/get-users-id-list_memberships

func (*Client) GetListTweets

func (c *Client) GetListTweets(list_id string, params Map) (*TweetsResponse, error)

Returns a list of Tweets from the specified List.

https://developer.twitter.com/en/docs/twitter-api/lists/list-tweets/api-reference/get-lists-id-tweets

func (*Client) GetMe

func (c *Client) GetMe(oauth_1a bool, params Map) (*UserResponse, error)

Returns information about an authorized user.

https://developer.twitter.com/en/docs/twitter-api/users/lookup/api-reference/get-users-me

func (*Client) GetMuted

func (c *Client) GetMuted(params Map) (*MutedUsersResponse, error)

Returns a list of users who are muted by the authenticating user.

https://developer.twitter.com/en/docs/twitter-api/users/mutes/api-reference/get-users-muting

func (*Client) GetOwnedLists

func (c *Client) GetOwnedLists(user_id string, params Map) (*ListsResponse, error)

Returns all Lists owned by the specified user.

https://developer.twitter.com/en/docs/twitter-api/lists/list-lookup/api-reference/get-users-id-owned_lists

func (*Client) GetPinnedLists

func (c *Client) GetPinnedLists(params Map) (*ListsResponse, error)

Returns the Lists pinned by a specified user.

https://developer.twitter.com/en/docs/twitter-api/lists/pinned-lists/api-reference/get-users-id-pinned_lists

func (*Client) GetQuoteTweets

func (c *Client) GetQuoteTweets(tweet_id string, params Map) (*TweetsResponse, error)

Returns Quote Tweets for a Tweet specified by the requested Tweet ID.

The Tweets returned by this endpoint count towards the Project-level `Tweet cap`.

https://developer.twitter.com/en/docs/twitter-api/tweets/quote-tweets/api-reference/get-tweets-id-quote_tweets

func (*Client) GetRecentTweetsCount

func (c *Client) GetRecentTweetsCount(query string, params Map) (*TweetsCountResponse, error)

The recent Tweet counts endpoint returns count of Tweets from the last seven days that match a search query.

https://developer.twitter.com/en/docs/twitter-api/tweets/counts/api-reference/get-tweets-counts-recent

func (*Client) GetRetweeters

func (c *Client) GetRetweeters(tweet_id string, params Map) (*UsersResponse, error)

Allows you to get information about who has Retweeted a Tweet.

Parameters

tweet_id: Tweet ID of the Tweet to request Retweeting users of.

params (keys):

"expansions", "media.fields", "place.fields",
"poll.fields", "tweet.fields", "user.fields",
"max_results", "pagination_token"

References

https://developer.twitter.com/en/docs/twitter-api/tweets/retweets/api-reference/get-tweets-id-retweeted_by

func (*Client) GetSpace

func (c *Client) GetSpace(space_id string, params Map) (*SpaceResponse, error)

Returns a variety of information about a single Space specified by the requested ID.

https://developer.twitter.com/en/docs/twitter-api/spaces/lookup/api-reference/get-spaces-id

func (*Client) GetSpaceBuyers

func (c *Client) GetSpaceBuyers(space_id string, params Map) (*UsersResponse, error)

Returns a list of user who purchased a ticket to the requested Space. You must authenticate the request using the Access Token of the creator of the requested Space.

https://developer.twitter.com/en/docs/twitter-api/spaces/lookup/api-reference/get-spaces-id-buyers

func (*Client) GetSpaceTweets

func (c *Client) GetSpaceTweets(space_id string, params Map) (*TweetsResponse, error)

Returns Tweets shared in the requested Spaces.

https://developer.twitter.com/en/docs/twitter-api/spaces/lookup/api-reference/get-spaces-id-tweets

func (*Client) GetSpacesByCreatorIDs

func (c *Client) GetSpacesByCreatorIDs(creator_ids []string, params Map) (*SpacesResponse, error)

Returns details about multiple live or scheduled Spaces created by the specified user IDs. Up to 100 comma-separated user IDs can be looked up using this method.

https://developer.twitter.com/en/docs/twitter-api/spaces/lookup/api-reference/get-spaces-by-creator-ids

func (*Client) GetSpacesBySpaceIDs

func (c *Client) GetSpacesBySpaceIDs(space_ids []string, params Map) (*SpacesResponse, error)

Returns details about multiple live or scheduled Spaces.

Up to 100 comma-separated Space IDs can be looked up using this method.

https://developer.twitter.com/en/docs/twitter-api/spaces/lookup/api-reference/get-spaces

func (*Client) GetTweet

func (c *Client) GetTweet(tweet_id string, params Map) (*TweetResponse, error)

Returns a variety of information about a single Tweet specified by the requested ID.

https://developer.twitter.com/en/docs/twitter-api/tweets/lookup/api-reference/get-tweets-id

func (*Client) GetTweets

func (c *Client) GetTweets(tweet_ids []string, params Map) (*TweetsResponse, error)

Returns a variety of information about the Tweet specified by the requested ID or list of IDs.

https://developer.twitter.com/en/docs/twitter-api/tweets/lookup/api-reference/get-tweets

func (*Client) GetUserByID

func (c *Client) GetUserByID(user_id string, params Map) (*UserResponse, error)

Returns a variety of information about a single user specified by the requested ID.

https://developer.twitter.com/en/docs/twitter-api/users/lookup/api-reference/get-users-id

func (*Client) GetUserByUsername

func (c *Client) GetUserByUsername(username string, params Map) (*UserResponse, error)

Returns a variety of information about a single user specified by the requested username.

https://developer.twitter.com/en/docs/twitter-api/users/lookup/api-reference/get-users-by-username-username

func (*Client) GetUserFollowers

func (c *Client) GetUserFollowers(user_id string, params Map) (*UsersResponse, error)

Returns a list of users who are followers of the specified user ID.

https://developer.twitter.com/en/docs/twitter-api/users/follows/api-reference/get-users-id-followers

func (*Client) GetUserFollowing

func (c *Client) GetUserFollowing(user_id string, params Map) (*UsersResponse, error)

Returns a list of users the specified user ID is following

https://developer.twitter.com/en/docs/twitter-api/users/follows/api-reference/get-users-id-following

func (*Client) GetUserMentions

func (c *Client) GetUserMentions(user_id string, params Map) (*TweetsResponse, error)

Returns Tweets mentioning a single user specified by the requested user ID. By default, the most recent ten Tweets are returned per request. Using pagination, up to the most recent 800 Tweets can be retrieved.

The Tweets returned by this endpoint count towards the Project-level `Tweet cap`.

https://developer.twitter.com/en/docs/twitter-api/tweets/timelines/api-reference/get-users-id-mentions

func (*Client) GetUserTweets

func (c *Client) GetUserTweets(user_id string, params Map) (*TweetsResponse, error)

Returns Tweets composed by a single user, specified by the requested user ID. By default, the most recent ten Tweets are returned per request. Using pagination, the most recent 3,200 Tweets can be retrieved.

The Tweets returned by this endpoint count towards the Project-level `Tweet cap`.

https://developer.twitter.com/en/docs/twitter-api/tweets/timelines/api-reference/get-users-id-tweets

func (*Client) GetUsersByIDs

func (c *Client) GetUsersByIDs(user_ids []string, params Map) (*UsersResponse, error)

Returns a variety of information about one or more users specified by the requested IDs.

https://developer.twitter.com/en/docs/twitter-api/users/lookup/api-reference/get-users

func (*Client) GetUsersByUsernames

func (c *Client) GetUsersByUsernames(usernames []string, params Map) (*UsersResponse, error)

Returns a variety of information about one or more users specified by the requested usernames.

usernames should not have @ at the beginning

https://developer.twitter.com/en/docs/twitter-api/users/lookup/api-reference/get-users-by

func (*Client) HideReply

func (c *Client) HideReply(reply_id string) (*HideReplyResponse, error)

Hides a reply to a Tweet

Parameters

reply_id:

Unique identifier of the Tweet to hide. The Tweet must belong to a
conversation initiated by the authenticating user.

References

https://developer.twitter.com/en/docs/twitter-api/tweets/hide-replies/api-reference/put-tweets-id-hidden

func (*Client) Like

func (c *Client) Like(tweet_id string) (*LikeResponse, error)

Like a Tweet.

Parameters

tweet_id: The ID of the Tweet that you would like to Like.

References

https://developer.twitter.com/en/docs/twitter-api/tweets/likes/api-reference/post-users-id-likesx

func (*Client) Mute

func (c *Client) Mute(target_user_id string) (*MuteResponse, error)

** Mutes ** // Allows an authenticated user ID to mute the target user.

https://developer.twitter.com/en/docs/twitter-api/users/mutes/api-reference/post-users-user_id-muting

func (*Client) PinList

func (c *Client) PinList(list_id string) (*PinResponse, error)

Enables the authenticated user to pin a List.

https://developer.twitter.com/en/docs/twitter-api/lists/pinned-lists/api-reference/post-users-id-pinned-lists

func (*Client) RemoveBookmark

func (c *Client) RemoveBookmark(tweet_id string) (*BookmarkResponse, error)

Allows a user or authenticated user ID to remove a Bookmark of a Tweet.

https://developer.twitter.com/en/docs/twitter-api/tweets/bookmarks/api-reference/delete-users-id-bookmarks-tweet_id

func (*Client) RemoveListMember

func (c *Client) RemoveListMember(list_id, user_id string) (*ListMemberResponse, error)

Enables the authenticated user to remove a member from a List they own.

https://developer.twitter.com/en/docs/twitter-api/lists/list-members/api-reference/delete-lists-id-members-user_id

func (*Client) Retweet

func (c *Client) Retweet(tweet_id string) (*RetweetResponse, error)

Causes the user ID to Retweet the target Tweet.

Parameters

tweet_id: The ID of the Tweet that you would like to Retweet.

References

https://developer.twitter.com/en/docs/twitter-api/tweets/retweets/api-reference/post-users-id-retweets

func (*Client) SearchAllTweets

func (c *Client) SearchAllTweets(query string, params Map) (*TweetsResponse, error)

The full-archive search endpoint returns the complete history of public Tweets matching a search query; since the first Tweet was created March 26, 2006.

This endpoint is only available to those users who have been approved for the `Academic Research product track`

The Tweets returned by this endpoint count towards the Project-level `Tweet cap`.

Parameters

query : str

One query for matching Tweets. Up to 1024 characters.

end_time : Union[datetime.datetime, str]

YYYY-MM-DDTHH:mm:ssZ (ISO 8601/RFC 3339). Used with ``start_time``.
The newest, most recent UTC timestamp to which the Tweets will be
provided. Timestamp is in second granularity and is exclusive (for
example, 12:00:01 excludes the first second of the minute). If used
without ``start_time``, Tweets from 30 days before ``end_time``
will be returned by default. If not specified, ``end_time`` will
default to [now - 30 seconds].

max_results : int

The maximum number of search results to be returned by a request. A
number between 10 and the system limit (currently 500). By default,
a request response will return 10 results.

next_token : str

This parameter is used to get the next 'page' of results. The value
used with the parameter is pulled directly from the response
provided by the API, and should not be modified. You can learn more
by visiting our page on `pagination`_.

since_id : Union[int, str]

Returns results with a Tweet ID greater than (for example, more
recent than) the specified ID. The ID specified is exclusive and
responses will not include it. If included with the same request as
a ``start_time`` parameter, only ``since_id`` will be used.

start_time : Union[datetime.datetime, str]

YYYY-MM-DDTHH:mm:ssZ (ISO 8601/RFC 3339). The oldest UTC timestamp
from which the Tweets will be provided. Timestamp is in second
granularity and is inclusive (for example, 12:00:01 includes the
first second of the minute). By default, a request will return
Tweets from up to 30 days ago if you do not include this parameter.

until_id: string

Returns results with a Tweet ID less than (that is, older than) the
specified ID. Used with ``since_id``. The ID specified is exclusive
and responses will not include it.

References

https://developer.twitter.com/en/docs/twitter-api/tweets/search/api-reference/get-tweets-search-all

Academic Research product track: https://developer.twitter.com/en/docs/projects/overview#product-track

Tweet cap: https://developer.twitter.com/en/docs/projects/overview#tweet-cap

pagination: https://developer.twitter.com/en/docs/twitter-api/tweets/search/integrate/paginate

func (*Client) SearchRecentTweets

func (c *Client) SearchRecentTweets(query string, params Map) (*TweetsResponse, error)

The recent search endpoint returns Tweets from the last seven days that match a search query.

The Tweets returned by this endpoint count towards the Project-level `Tweet cap`.

Parameters

query : str

One rule for matching Tweets. If you are using a
`Standard Project`_ at the Basic `access level`_, you can use the
basic set of `operators`_ and can make queries up to 512 characters
long. If you are using an `Academic Research Project`_ at the Basic
access level, you can use all available operators and can make
queries up to 1,024 characters long.

end_time : Union[datetime.datetime, str]

YYYY-MM-DDTHH:mm:ssZ (ISO 8601/RFC 3339). The newest, most recent
UTC timestamp to which the Tweets will be provided. Timestamp is in
second granularity and is exclusive (for example, 12:00:01 excludes
the first second of the minute). By default, a request will return
Tweets from as recent as 30 seconds ago if you do not include this
parameter.

max_results : int

The maximum number of search results to be returned by a request. A
number between 10 and 100. By default, a request response will
return 10 results.

next_token : str

This parameter is used to get the next 'page' of results. The value
used with the parameter is pulled directly from the response
provided by the API, and should not be modified.

since_id : Union[int, str]

Returns results with a Tweet ID greater than (that is, more recent
than) the specified ID. The ID specified is exclusive and responses
will not include it. If included with the same request as a
``start_time`` parameter, only ``since_id`` will be used.

start_time : Union[datetime.datetime, str]

YYYY-MM-DDTHH:mm:ssZ (ISO 8601/RFC 3339). The oldest UTC timestamp
(from most recent seven days) from which the Tweets will be
provided. Timestamp is in second granularity and is inclusive (for
example, 12:00:01 includes the first second of the minute). If
included with the same request as a ``since_id`` parameter, only
``since_id`` will be used. By default, a request will return Tweets
from up to seven days ago if you do not include this parameter.

until_id : Union[int, str]

Returns results with a Tweet ID less than (that is, older than) the
specified ID. The ID specified is exclusive and responses will not
include it.

References

https://developer.twitter.com/en/docs/twitter-api/tweets/search/api-reference/get-tweets-search-recent

Tweet cap: https://developer.twitter.com/en/docs/projects/overview#tweet-cap

Standard Project: https://developer.twitter.com/en/docs/projects

access level: https://developer.twitter.com/en/products/twitter-api/early-access/guide.html#na_1

operators: https://developer.twitter.com/en/docs/twitter-api/tweets/search/integrate/build-a-query

Academic Research Project: https://developer.twitter.com/en/docs/projects

func (*Client) SearchSpaces

func (c *Client) SearchSpaces(query string, params Map) (*SpacesResponse, error)

Return live or scheduled Spaces matching your specified search terms

https://developer.twitter.com/en/docs/twitter-api/spaces/search/api-reference/get-spaces-search

func (*Client) SetDefaultOAuth

func (c *Client) SetDefaultOAuth(caller string) *Client

TODO: Integrate this to get_request, for each request, see if the oauth method is default, set it!, but we need the caller function? or maybe we can call this function inside each method

func (*Client) SetOAuth

func (c *Client) SetOAuth(oauth_type OAuthType) *Client

func (*Client) UnBlock

func (c *Client) UnBlock(target_user_id string) (*BlockResponse, error)

The request succeeds with no action when the user sends a request to a user they're not blocking or have already unblocked.

https://developer.twitter.com/en/docs/twitter-api/users/blocks/api-reference/delete-users-user_id-blocking

func (*Client) UnHideReply

func (c *Client) UnHideReply(reply_id string) (*HideReplyResponse, error)

Unhides a reply to a Tweet

Parameters

reply_id:

	Unique identifier of the Tweet to unhide. The Tweet must belong to
 a conversation initiated by the authenticating user.

References

https://developer.twitter.com/en/docs/twitter-api/tweets/hide-replies/api-reference/put-tweets-id-hidden

func (*Client) UnMute

func (c *Client) UnMute(target_user_id string) (*MuteResponse, error)

Allows an authenticated user ID to unmute the target user.

The request succeeds with no action when the user sends a request to a user they're not muting or have already unmuted.

https://developer.twitter.com/en/docs/twitter-api/users/mutes/api-reference/delete-users-user_id-muting

func (*Client) UnRetweet

func (c *Client) UnRetweet(tweet_id string) (*RetweetResponse, error)

Allows an authenticated user ID to remove the Retweet of a Tweet.

The request succeeds with no action when the user sends a request to a user they're not Retweeting the Tweet or have already removed the Retweet of.

Parameters

tweet_id: The ID of the Tweet that you would like to remove the Retweet of.

References

https://developer.twitter.com/en/docs/twitter-api/tweets/retweets/api-reference/delete-users-id-retweets-tweet_id

func (*Client) UnfollowUser

func (c *Client) UnfollowUser(target_user_id string) (*FollowResponse, error)

Allows a user ID to unfollow another user.

The request succeeds with no action when the authenticated user sends a request to a user they're not following or have already unfollowed.

https://developer.twitter.com/en/docs/twitter-api/users/follows/api-reference/delete-users-source_id-following

func (*Client) Unlike

func (c *Client) Unlike(tweet_id string) (*LikeResponse, error)

Unlike a Tweet.

The request succeeds with no action when the user sends a request to a user they're not liking the Tweet or have already unliked the Tweet.

Parameters

tweet_id: The ID of the Tweet that you would like to unlike.

References

https://developer.twitter.com/en/docs/twitter-api/tweets/likes/api-reference/delete-users-id-likes-tweet_id

func (*Client) UpdateList

func (c *Client) UpdateList(list_id string, name string, description string, private bool, params Map) (*UpdateListResponse, error)

Enables the authenticated user to update the meta data of a specified List that they own.

https://developer.twitter.com/en/docs/twitter-api/lists/manage-lists/api-reference/put-lists-id

type ComplianceJobResponse

type ComplianceJobResponse struct {
	Data       entities.ComplianceJob
	Includes   IncludesEntity
	Errors     []ErrorEntity
	Meta       MetaEntity
	RateLimits RateLimits
}

func (*ComplianceJobResponse) Parse

func (r *ComplianceJobResponse) Parse(raw_response *http.Response) (*ComplianceJobResponse, error)

type ComplianceJobsResponse

type ComplianceJobsResponse struct {
	Data       []entities.ComplianceJob
	Includes   IncludesEntity
	Errors     []ErrorEntity
	Meta       MetaEntity
	RateLimits RateLimits
}

func (*ComplianceJobsResponse) Parse

func (r *ComplianceJobsResponse) Parse(raw_response *http.Response) (*ComplianceJobsResponse, error)

type Config

type Config struct {
	ConsumerKey    string
	ConsumerSecret string
	AccessToken    string
	AccessSecret   string
	BearerToken    string
}

type DeleteResponse

type DeleteResponse struct {
	Data struct {
		Deleted bool `json:"deleted"`
	}
	Includes   IncludesEntity
	Errors     []ErrorEntity
	Meta       MetaEntity
	RateLimits RateLimits
}

func (*DeleteResponse) Parse

func (r *DeleteResponse) Parse(raw_response *http.Response) (*DeleteResponse, error)

type ErrorEntity

type ErrorEntity struct {
	Parameters map[string]interface{} `json:"parameters"`
	Message    string                 `json:"message"`
}

type FollowResponse

type FollowResponse struct {
	Data struct {
		Following bool `json:"following"`
	}
	Includes   IncludesEntity
	Errors     []ErrorEntity
	Meta       MetaEntity
	RateLimits RateLimits
}

func (*FollowResponse) Parse

func (r *FollowResponse) Parse(raw_response *http.Response) (*FollowResponse, error)

type HideReplyResponse

type HideReplyResponse struct {
	Data struct {
		Hidden bool `json:"hidden"`
	}
	Includes   IncludesEntity
	Errors     []ErrorEntity
	Meta       MetaEntity
	RateLimits RateLimits
}

func (*HideReplyResponse) Parse

func (r *HideReplyResponse) Parse(raw_response *http.Response) (*HideReplyResponse, error)

type IncludeGeo

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

type IncludesEntity

type IncludesEntity struct {
	Users  []entities.User  `json:"users"`
	Tweets []entities.Tweet `json:"tweets"`
	Polls  []Poll           `json:"polls"` // Do you remember if "poll" in the client?
	Places []Place          `json:"places"`
	Media  []Media          `json:"media"`
}

type LikeResponse

type LikeResponse struct {
	Data struct {
		Liked bool `json:"liked"`
	}
	Includes   IncludesEntity
	Errors     []ErrorEntity
	Meta       MetaEntity
	RateLimits RateLimits
}

func (*LikeResponse) Parse

func (r *LikeResponse) Parse(raw_response *http.Response) (*LikeResponse, error)

type List

type List struct {
	ID            string    `json:"id"`
	Name          string    `json:"name"`
	CreatedAt     time.Time `json:"created_at,omitempty"`
	Private       bool      `json:"private,omitempty"`
	FollowerCount int       `json:"follower_count,omitempty"`
	MemberCount   int       `json:"member_count,omitempty"`
	OwnerID       string    `json:"owner_id,omitempty"`
	Description   string    `json:"description,omitempty"`
}

type ListMemberResponse

type ListMemberResponse struct {
	Data struct {
		IsMember bool `json:"is_member"`
	}
	Includes   IncludesEntity
	Errors     []ErrorEntity
	Meta       MetaEntity
	RateLimits RateLimits
}

func (*ListMemberResponse) Parse

func (r *ListMemberResponse) Parse(raw_response *http.Response) (*ListMemberResponse, error)

type ListResponse

type ListResponse struct {
	Data       List
	Includes   IncludesEntity
	Errors     []ErrorEntity
	Meta       MetaEntity
	RateLimits RateLimits
}

func (*ListResponse) Parse

func (r *ListResponse) Parse(raw_response *http.Response) (*ListResponse, error)

type ListsResponse

type ListsResponse struct {
	Data       []List
	Includes   IncludesEntity
	Errors     []ErrorEntity
	Meta       MetaEntity
	RateLimits RateLimits
	CallerData CallerData
	Caller     func(string, Map) (*ListsResponse, error)
}

func (*ListsResponse) NextPage

func (r *ListsResponse) NextPage() (*ListsResponse, error)

func (*ListsResponse) Parse

func (r *ListsResponse) Parse(raw_response *http.Response) (*ListsResponse, error)

type Map

type Map map[string]interface{}

type Media

type Media struct {
	MediaKey         string         `json:"media_key"`
	Type             string         `json:"type"`
	Url              string         `json:"url"`
	DurationMs       int            `json:"duration_ms,omitempty"`
	Height           int            `json:"height,omitempty"`
	NonPublicMetrics map[string]int `json:"non_public_metrics,omitempty"`
	OrganicMetrics   map[string]int `json:"organic_metrics,omitempty"`
	PreviewImageUrl  string         `json:"preview_image_url,omitempty"`
	PromotedMetrics  map[string]int `json:"promoted_metrics,omitempty"`
	PublicMetrics    map[string]int `json:"public_metrics,omitempty"`
	Width            int            `json:"width,omitempty"`
	AltText          int            `json:"alt_text,omitempty"`
}

type MetaEntity

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

*** Basic Entities *** //

type MuteResponse

type MuteResponse struct {
	Data struct {
		Muting bool `json:"muting"`
	}
	Includes   IncludesEntity
	Errors     []ErrorEntity
	Meta       MetaEntity
	RateLimits RateLimits
}

func (*MuteResponse) Parse

func (r *MuteResponse) Parse(raw_response *http.Response) (*MuteResponse, error)

type MutedUsersResponse

type MutedUsersResponse struct {
	Data       []entities.User
	Includes   IncludesEntity
	Errors     []ErrorEntity
	Meta       MetaEntity
	RateLimits RateLimits
	CallerData CallerData
	Caller     func(Map) (*MutedUsersResponse, error)
}

func (*MutedUsersResponse) NextPage

func (r *MutedUsersResponse) NextPage() (*MutedUsersResponse, error)

func (*MutedUsersResponse) Parse

func (r *MutedUsersResponse) Parse(raw_response *http.Response) (*MutedUsersResponse, error)

type OAuthType

type OAuthType int8
const (
	OAuth_Default OAuthType = 0
	OAuth_1a      OAuthType = 1
	OAuth_2       OAuthType = 2
)

type PinResponse

type PinResponse struct {
	Data struct {
		Pinned bool `json:"pinned"`
	}
	Includes   IncludesEntity
	Errors     []ErrorEntity
	Meta       MetaEntity
	RateLimits RateLimits
}

func (*PinResponse) Parse

func (r *PinResponse) Parse(raw_response *http.Response) (*PinResponse, error)

type Place

type Place struct {
	FullName        string     `json:"full_name"`
	ID              string     `json:"id"`
	ContainedWithin string     `json:"contained_within,omitempty"`
	Country         string     `json:"country,omitempty"`
	CountryCode     string     `json:"country_code,omitempty"`
	Geo             IncludeGeo `json:"geo,omitempty"`
	Name            string     `json:"name,omitempty"`
	PlaceType       string     `json:"place_type,omitempty"`
}

type Poll

type Poll struct {
	ID              string       `json:"id"`
	Options         []PollOption `json:"options"`
	DurationMinutes int          `json:"duration_minutes,omitempty"`
	EndDatetime     time.Time    `json:"end_datetime,omitempty"`
	VotingStatus    string       `json:"voting_status,omitempty"`
}

type PollOption

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

type RateLimits

type RateLimits struct {
	Limit          int   `json:"x-rate-limit"`
	Remaining      int   `json:"x-rate-limit-remaining"`
	ResetTimestamp int64 `json:"x-rate-limit-reset"` // Isn't this a time.Time?
}

func (*RateLimits) Set

func (r *RateLimits) Set(header http.Header)

type RetweetResponse

type RetweetResponse struct {
	Data struct {
		Retweeted bool `json:"retweeted"`
	}
	Includes   IncludesEntity
	Errors     []ErrorEntity
	Meta       MetaEntity
	RateLimits RateLimits
}

func (*RetweetResponse) Parse

func (r *RetweetResponse) Parse(raw_response *http.Response) (*RetweetResponse, error)

type SpaceResponse

type SpaceResponse struct {
	Data       entities.Space
	Includes   IncludesEntity
	Errors     []ErrorEntity
	Meta       MetaEntity
	RateLimits RateLimits
}

func (*SpaceResponse) Parse

func (r *SpaceResponse) Parse(raw_response *http.Response) (*SpaceResponse, error)

type SpacesResponse

type SpacesResponse struct {
	Data       entities.Space
	Includes   IncludesEntity
	Errors     []ErrorEntity
	Meta       MetaEntity
	RateLimits RateLimits
}

func (*SpacesResponse) Parse

func (r *SpacesResponse) Parse(raw_response *http.Response) (*SpacesResponse, error)

type SpecialError

type SpecialError struct {
	Title  string `json:"title"`
	Type   string `json:"type"`
	Status int    `json:"status"`
	Detail string `json:"detail"`
}

func (*SpecialError) Error

func (e *SpecialError) Error() error

type TweetResponse

type TweetResponse struct {
	Data       entities.Tweet
	Includes   IncludesEntity
	Errors     []ErrorEntity
	Meta       MetaEntity
	RateLimits RateLimits
}

*** Response Entities *** //

func (*TweetResponse) Parse

func (r *TweetResponse) Parse(raw_response *http.Response) (*TweetResponse, error)

type TweetsCountResponse

type TweetsCountResponse struct {
	Data struct {
		End        time.Time `json:"end"`
		Start      time.Time `json:"start"`
		TweetCount int       `json:"tweet_count"`
	}
	Meta struct {
		// TODO: Also there is a "meta" field in the response that is a object
		TotalTweetCount int    `json:"total_tweet_count"`
		NextToken       string `json:"next_token"`
	}
	Includes   IncludesEntity
	Errors     []ErrorEntity
	RateLimits RateLimits
}

func (*TweetsCountResponse) Parse

func (r *TweetsCountResponse) Parse(raw_response *http.Response) (*TweetsCountResponse, error)

type TweetsResponse

type TweetsResponse struct {
	Data       []entities.Tweet
	Includes   IncludesEntity
	Errors     []ErrorEntity
	Meta       MetaEntity
	RateLimits RateLimits
	CallerData CallerData
	Caller     func(string, Map) (*TweetsResponse, error)
}

func (*TweetsResponse) NextPage

func (r *TweetsResponse) NextPage() (*TweetsResponse, error)

func (*TweetsResponse) Parse

func (r *TweetsResponse) Parse(raw_response *http.Response) (*TweetsResponse, error)

type UpdateListResponse

type UpdateListResponse struct {
	Data struct {
		Updated bool `json:"updated"`
	}
	Includes   IncludesEntity
	Errors     []ErrorEntity
	Meta       MetaEntity
	RateLimits RateLimits
}

func (*UpdateListResponse) Parse

func (r *UpdateListResponse) Parse(raw_response *http.Response) (*UpdateListResponse, error)

type UserResponse

type UserResponse struct {
	Data       entities.User
	Includes   IncludesEntity
	Errors     []ErrorEntity
	Meta       MetaEntity
	RateLimits RateLimits
}

func (*UserResponse) Parse

func (r *UserResponse) Parse(raw_response *http.Response) (*UserResponse, error)

type UsersResponse

type UsersResponse struct {
	Data       []entities.User
	Includes   IncludesEntity
	Errors     []ErrorEntity
	Meta       MetaEntity
	RateLimits RateLimits
	CallerData CallerData
	Caller     func(string, Map) (*UsersResponse, error)
}

func (*UsersResponse) NextPage

func (r *UsersResponse) NextPage() (*UsersResponse, error)

func (*UsersResponse) Parse

func (r *UsersResponse) Parse(raw_response *http.Response) (*UsersResponse, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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