Documentation ¶
Overview ¶
Package anaconda provides structs and functions for accessing version 1.1 of the Twitter API.
Successful API queries return native Go structs that can be used immediately, with no need for type assertions.
Authentication ¶
If you already have the access token (and secret) for your user (Twitter provides this for your own account on the developer portal), creating the client is simple:
anaconda.SetConsumerKey("your-consumer-key") anaconda.SetConsumerSecret("your-consumer-secret") api := anaconda.NewTwitterApi("your-access-token", "your-access-token-secret")
Queries ¶
Executing queries on an authenticated TwitterApi struct is simple.
searchResult, _ := api.GetSearch("golang", nil) for _ , tweet := range searchResult.Statuses { fmt.Print(tweet.Text) }
Certain endpoints allow separate optional parameter; if desired, these can be passed as the final parameter.
v := url.Values{} v.Set("count", "30") result, err := api.GetSearch("golang", v)
Endpoints ¶
Anaconda implements most of the endpoints defined in the Twitter API documentation: https://dev.twitter.com/docs/api/1.1. For clarity, in most cases, the function name is simply the name of the HTTP method and the endpoint (e.g., the endpoint `GET /friendships/incoming` is provided by the function `GetFriendshipsIncoming`).
In a few cases, a shortened form has been chosen to make life easier (for example, retweeting is simply the function `Retweet`)
More detailed information about the behavior of each particular endpoint can be found at the official Twitter API documentation.
Index ¶
- Constants
- func AuthorizationURL(oauthClient *oauth.Client, callback string) (string, *oauth.Credentials, error)
- func GetCredentials(oauthClient *oauth.Client, tempCred *oauth.Credentials, verifier string) (*oauth.Credentials, url.Values, error)
- func NewOauthClient(consumer_key string, consumer_secret string) *oauth.Client
- type AddUserToListResponse
- type ApiError
- type Contributor
- type Coordinates
- type Cursor
- type DirectMessage
- type DisconnectMessage
- type Entities
- type Event
- type EventList
- type EventTweet
- type FlowMeter
- type FollowersPage
- type FriendsList
- type Friendship
- type Image
- type LimitNotice
- type List
- type ListResponse
- type Location
- type LocationDeletionNotice
- type Logger
- type Media
- type MediaSize
- type MediaSizes
- type OEmbed
- type Place
- type Relationship
- type RelationshipResponse
- type SearchMetadata
- type SearchResponse
- type Source
- type StallWarning
- type StatusDeletionNotice
- type StatusWithheldNotice
- type Stream
- type Target
- type TooManyFollow
- type Trend
- type TrendResponse
- type Tweet
- type TwitterApi
- func (a TwitterApi) AddUserToList(screenName string, listID int64, v url.Values) (users []User, err error)
- func (a TwitterApi) Block(v url.Values) (user User, err error)
- func (a TwitterApi) BlockUser(screenName string, v url.Values) (user User, err error)
- func (a TwitterApi) BlockUserId(id int64, v url.Values) (user User, err error)
- func (c *TwitterApi) Close()
- func (c *TwitterApi) ConfigureRedis(host string, port int, db int)
- func (a TwitterApi) CreateList(name, description string, v url.Values) (list List, err error)
- func (a TwitterApi) DeleteTweet(id int64, trimUser bool) (tweet Tweet, err error)
- func (c *TwitterApi) DisableThrottling()
- func (c *TwitterApi) EnableThrottling(rate time.Duration, bufferSize int64)
- func (a TwitterApi) Favorite(id int64) (rt Tweet, err error)
- func (a TwitterApi) FollowUser(screenName string) (user User, err error)
- func (a TwitterApi) FollowUserId(userId int64, v url.Values) (user User, err error)
- func (a TwitterApi) GetAvailableTrends(v url.Values) (locations []Location, err error)
- func (a TwitterApi) GetBlocksIds(v url.Values) (c Cursor, err error)
- func (a TwitterApi) GetBlocksList(v url.Values) (c UserCursor, err error)
- func (a TwitterApi) GetClosestTrends(lat string, long string, v url.Values) (location Location, err error)
- func (c *TwitterApi) GetDelay() time.Duration
- func (a TwitterApi) GetDirectMessages(v url.Values) (messages []DirectMessage, err error)
- func (a TwitterApi) GetDirectMessagesSent(v url.Values) (messages []DirectMessage, err error)
- func (a TwitterApi) GetDirectMessagesShow(v url.Values) (messages []DirectMessage, err error)
- func (a TwitterApi) GetFavorites(v url.Values) (favorites []Tweet, err error)
- func (a TwitterApi) GetFollowersIds(v url.Values) (c Cursor, err error)
- func (a TwitterApi) GetFollowersList(v url.Values) (c UserCursor, err error)
- func (a TwitterApi) GetFollowersListAll(v url.Values) (result chan FollowersPage)
- func (a TwitterApi) GetFollowersUser(id int64, v url.Values) (c Cursor, err error)
- func (a TwitterApi) GetFriendsIds(v url.Values) (c Cursor, err error)
- func (a TwitterApi) GetFriendsIdsAll(v url.Values) (c Cursor, err error)
- func (a TwitterApi) GetFriendsList(v url.Values) (c UserCursor, err error)
- func (a TwitterApi) GetFriendsUser(id int64, v url.Values) (c Cursor, err error)
- func (a TwitterApi) GetFriendshipsIncoming(v url.Values) (c Cursor, err error)
- func (a TwitterApi) GetFriendshipsLookup(v url.Values) (friendships []Friendship, err error)
- func (a TwitterApi) GetFriendshipsNoRetweets() (ids []int64, err error)
- func (a TwitterApi) GetFriendshipsOutgoing(v url.Values) (c Cursor, err error)
- func (a TwitterApi) GetFriendshipsShow(v url.Values) (relationshipResponse RelationshipResponse, err error)
- func (a TwitterApi) GetHomeTimeline(v url.Values) (timeline []Tweet, err error)
- func (a TwitterApi) GetListTweets(listID int64, includeRTs bool, v url.Values) (tweets []Tweet, err error)
- func (a TwitterApi) GetListsOwnedBy(userID int64, v url.Values) (lists []List, err error)
- func (a TwitterApi) GetMentionsTimeline(v url.Values) (timeline []Tweet, err error)
- func (a TwitterApi) GetOEmbed(v url.Values) (o OEmbed, err error)
- func (a TwitterApi) GetOEmbedId(id int64, v url.Values) (o OEmbed, err error)
- func (a TwitterApi) GetPlaceTrends(id string, exclude string, v url.Values) (trendResponse []TrendResponse, err error)
- func (a TwitterApi) GetRetweets(id int64, v url.Values) (tweets []Tweet, err error)
- func (a TwitterApi) GetRetweetsOfMe(v url.Values) (tweets []Tweet, err error)
- func (a TwitterApi) GetSearch(queryString string, v url.Values) (sr SearchResponse, err error)
- func (a TwitterApi) GetSelf(v url.Values) (u User, err error)
- func (a TwitterApi) GetTweet(id int64, v url.Values) (tweet Tweet, err error)
- func (a TwitterApi) GetTweetsLookupByIds(ids []int64, v url.Values) (tweet []Tweet, err error)
- func (a TwitterApi) GetUserSearch(searchTerm string, v url.Values) (u []User, err error)
- func (a TwitterApi) GetUserTimeline(v url.Values) (timeline []Tweet, err error)
- func (a TwitterApi) GetUsersLookup(usernames string, v url.Values) (u []User, err error)
- func (a TwitterApi) GetUsersLookupByIds(ids []int64, v url.Values) (u []User, err error)
- func (a TwitterApi) GetUsersShow(username string, v url.Values) (u User, err error)
- func (a TwitterApi) GetUsersShowById(id int64, v url.Values) (u User, err error)
- func (a TwitterApi) PostDMToScreenName(text, screenName string) (message DirectMessage, err error)
- func (a TwitterApi) PostDMToUserId(text string, userId int64) (message DirectMessage, err error)
- func (a TwitterApi) PostTweet(status string, v url.Values) (tweet Tweet, err error)
- func (a TwitterApi) PublicStreamFilter(v url.Values) (stream Stream)
- func (a TwitterApi) PublicStreamFirehose(v url.Values) (stream Stream)
- func (a TwitterApi) PublicStreamSample(v url.Values) (stream Stream)
- func (c *TwitterApi) ReturnRateLimitError(b bool)
- func (a TwitterApi) Retweet(id int64, trimUser bool) (rt Tweet, err error)
- func (c *TwitterApi) SetDelay(t time.Duration)
- func (c *TwitterApi) SetLogger(l Logger)
- func (c *TwitterApi) SetScreenName(n string)
- func (a TwitterApi) SiteStream(v url.Values) (stream Stream)
- func (a TwitterApi) Unblock(v url.Values) (user User, err error)
- func (a TwitterApi) UnblockUser(screenName string, v url.Values) (user User, err error)
- func (a TwitterApi) UnblockUserId(id int64, v url.Values) (user User, err error)
- func (a TwitterApi) Unfavorite(id int64) (rt Tweet, err error)
- func (a TwitterApi) UnfollowUser(screenname string) (u User, err error)
- func (a TwitterApi) UnfollowUserId(userId int64) (u User, err error)
- func (a TwitterApi) UploadMedia(base64String string) (media Media, err error)
- func (a TwitterApi) UserStream(v url.Values) (stream Stream)
- func (a TwitterApi) VerifyCredentials() (ok bool, err error)
- type TwitterError
- type TwitterErrorResponse
- type UrlEntity
- type User
- type UserCursor
- type UserWithheldNotice
Examples ¶
Constants ¶
const ( //Error code defintions match the Twitter documentation //https://dev.twitter.com/docs/error-codes-responses TwitterErrorCouldNotAuthenticate = 32 TwitterErrorDoesNotExist = 34 TwitterErrorAccountSuspended = 64 TwitterErrorApi1Deprecation = 68 //This should never be needed TwitterErrorRateLimitExceeded = 88 TwitterErrorInvalidToken = 89 TwitterErrorOverCapacity = 130 TwitterErrorInternalError = 131 TwitterErrorCouldNotAuthenticateYou = 135 TwitterErrorStatusIsADuplicate = 187 TwitterErrorBadAuthenticationData = 215 TwitterErrorUserMustVerifyLogin = 231 // Undocumented by Twitter, but may be returned instead of 34 TwitterErrorDoesNotExist2 = 144 )
const ( BaseUrlUserStream = "https://userstream.twitter.com/1.1" BaseUrlSiteStream = "https://sitestream.twitter.com/1.1" BaseUrlStream = "https://stream.twitter.com/1.1" )
const ( BaseUrlV1 = "https://api.twitter.com/1" BaseUrl = "https://api.twitter.com/1.1" UploadBaseUrl = "https://upload.twitter.com/1.1" )
const DEFAULT_CAPACITY = 5
const DEFAULT_DELAY = 0 * time.Second
Variables ¶
This section is empty.
Functions ¶
func AuthorizationURL ¶
func AuthorizationURL(oauthClient *oauth.Client, callback string) (string, *oauth.Credentials, error)
AuthorizationURL generates the authorization URL for the first part of the OAuth handshake. Redirect the user to this URL. This assumes that the consumer key has already been set (using SetConsumerKey).
func GetCredentials ¶
func GetCredentials(oauthClient *oauth.Client, tempCred *oauth.Credentials, verifier string) (*oauth.Credentials, url.Values, error)
Types ¶
type AddUserToListResponse ¶
type AddUserToListResponse struct {
Users []User `json:"users"`
}
type ApiError ¶
type ApiError struct { StatusCode int Header http.Header Body string Decoded TwitterErrorResponse URL *url.URL }
func NewApiError ¶
func (*ApiError) RateLimitCheck ¶
Check to see if an error is a Rate Limiting error. If so, find the next available window in the header. Use like so:
if aerr, ok := err.(*ApiError); ok { if isRateLimitError, nextWindow := aerr.RateLimitCheck(); isRateLimitError { <-time.After(nextWindow.Sub(time.Now())) } }
type Contributor ¶
type Contributor struct { Id int64 `json:"id"` IdStr string `json:"id_str"` ScreenName string `json:"screen_name"` }
Could also use User, since the fields match, but only these fields are possible in Contributor
type Coordinates ¶
type DirectMessage ¶
type DirectMessage struct { CreatedAt string `json:"created_at"` Entities Entities `json:"entities"` Id int64 `json:"id"` IdStr string `json:"id_str"` Recipient User `json:"recipient"` RecipientId int64 `json:"recipient_id"` RecipientScreenName string `json:"recipient_screen_name"` Sender User `json:"sender"` SenderId int64 `json:"sender_id"` SenderScreenName string `json:"sender_screen_name"` Text string `json:"text"` }
type DisconnectMessage ¶
type Entities ¶
type Entities struct { int Text string } Symbols []struct { Indices []int Text string } Urls []struct { Indices []int Url string Display_url string Expanded_url string } Url UrlEntity User_mentions []struct { Name string Indices []int Screen_name string Id int64 Id_str string } Media []struct { Id int64 Id_str string Media_url string Media_url_https string Url string Display_url string Expanded_url string Sizes MediaSizes Type string Indices []int } }Indices []
type EventTweet ¶
type FlowMeter ¶
type FlowMeter struct {
// contains filtered or unexported fields
}
Measure flow of tweets
type FollowersPage ¶
type FriendsList ¶
type FriendsList []int64
type Friendship ¶
type LimitNotice ¶
type LimitNotice struct {
Track int64 `json:"track"`
}
type List ¶
type List struct { Slug string `json:"slug"` Name string `json:"name"` URL string `json:"uri"` CreatedAt string `json:"created_at"` Id int64 `json:"id"` SubscriberCount int64 `json:"subscriber_count"` MemberCount int64 `json:"member_count"` Mode string `json:"mode"` FullName string `json:"full_name"` Description string `json:"description"` User User `json:"user"` Following bool `json:"following"` }
type ListResponse ¶
type Location ¶
type Location struct { Country string `json:"country,omitempty"` CountryCode string `json:"countryCode,omitempty"` Name string `json:"name"` ParentId int64 `json:"parentid,omitempty"` PlaceType struct { Code int64 `json:"code"` Name string `json:"name"` } `json:"placeType,,omitempty"` WoeId int64 `json:"woeid"` // contains filtered or unexported fields }
type LocationDeletionNotice ¶
type Logger ¶
type Logger interface { Fatal(args ...interface{}) Fatalf(format string, args ...interface{}) Panic(args ...interface{}) Panicf(format string, args ...interface{}) // Log functions Critical(args ...interface{}) Criticalf(format string, args ...interface{}) Error(args ...interface{}) Errorf(format string, args ...interface{}) Warning(args ...interface{}) Warningf(format string, args ...interface{}) Notice(args ...interface{}) Noticef(format string, args ...interface{}) Info(args ...interface{}) Infof(format string, args ...interface{}) Debug(args ...interface{}) Debugf(format string, args ...interface{}) }
The Logger interface provides optional logging ability for the streaming API. It can also be used to log the rate limiting headers if desired.
var BasicLogger Logger
BasicLogger is the equivalent of using log from the standard library to print to STDERR.
type MediaSizes ¶
type Place ¶
type Place struct { Attributes map[string]string `json:"attributes"` BoundingBox struct { Coordinates [][][]float64 `json:"coordinates"` Type string `json:"type"` } `json:"bounding_box"` ContainedWithin []struct { Attributes map[string]string `json:"attributes"` BoundingBox struct { Coordinates [][][]float64 `json:"coordinates"` Type string `json:"type"` } `json:"bounding_box"` Country string `json:"country"` CountryCode string `json:"country_code"` FullName string `json:"full_name"` ID string `json:"id"` Name string `json:"name"` PlaceType string `json:"place_type"` URL string `json:"url"` } `json:"contained_within"` Country string `json:"country"` CountryCode string `json:"country_code"` FullName string `json:"full_name"` Geometry struct { Coordinates [][][]float64 `json:"coordinates"` Type string `json:"type"` } `json:"geometry"` ID string `json:"id"` Name string `json:"name"` PlaceType string `json:"place_type"` Polylines []string `json:"polylines"` URL string `json:"url"` }
type Relationship ¶
type RelationshipResponse ¶
type RelationshipResponse struct {
Relationship Relationship `json:"relationship"`
}
type SearchMetadata ¶
type SearchMetadata struct { CompletedIn float32 `json:"completed_in"` MaxId int64 `json:"max_id"` MaxIdString string `json:"max_id_str"` Query string `json:"query"` RefreshUrl string `json:"refresh_url"` Count int `json:"count"` SinceId int64 `json:"since_id"` SinceIdString string `json:"since_id_str"` NextResults string `json:"next_results"` }
type SearchResponse ¶
type SearchResponse struct { Statuses []Tweet `json:"statuses"` Metadata SearchMetadata `json:"search_metadata"` }
func (*SearchResponse) GetNext ¶
func (sr *SearchResponse) GetNext(a *TwitterApi) (SearchResponse, error)
type StallWarning ¶
type StatusDeletionNotice ¶
type StatusWithheldNotice ¶
type Stream ¶
type TooManyFollow ¶
type TrendResponse ¶
type Tweet ¶
type Tweet struct { Contributors []Contributor `json:"contributors"` // Not yet generally available to all, so hard to test Coordinates *Coordinates `json:"coordinates"` CreatedAt string `json:"created_at"` Entities Entities `json:"entities"` FavoriteCount int `json:"favorite_count"` Favorited bool `json:"favorited"` FilterLevel string `json:"filter_level"` Id int64 `json:"id"` IdStr string `json:"id_str"` InReplyToScreenName string `json:"in_reply_to_screen_name"` InReplyToStatusID int64 `json:"in_reply_to_status_id"` InReplyToStatusIdStr string `json:"in_reply_to_status_id_str"` InReplyToUserID int64 `json:"in_reply_to_user_id"` InReplyToUserIdStr string `json:"in_reply_to_user_id_str"` Lang string `json:"lang"` Place Place `json:"place"` PossiblySensitive bool `json:"possibly_sensitive"` RetweetCount int `json:"retweet_count"` Retweeted bool `json:"retweeted"` RetweetedStatus *Tweet `json:"retweeted_status"` Source string `json:"source"` Scopes map[string]string `json:"scopes"` Text string `json:"text"` Truncated bool `json:"truncated"` User User `json:"user"` WithheldCopyright bool `json:"withheld_copyright"` WithheldInCountries []string `json:"withheld_in_countries"` WithheldScope string `json:"withheld_scope"` }
func (Tweet) CreatedAtTime ¶
CreatedAtTime is a convenience wrapper that returns the Created_at time, parsed as a time.Time struct
func (Tweet) HasCoordinates ¶
HasCoordinates is a helper function to easily determine if a Tweet has coordinates associated with it
type TwitterApi ¶
type TwitterApi struct { Credentials *oauth.Credentials ScreenName string OauthClient *oauth.Client HttpClient *http.Client RedisClient *redis.Client // Currently used only for the streaming API // and for checking rate-limiting headers // Default logger is silent Log Logger // contains filtered or unexported fields }
func NewTwitterApi ¶
func NewTwitterApi(consumer_token string, consumer_secret string, access_token string, access_token_secret string) *TwitterApi
NewTwitterApi takes an user-specific access token and secret and returns a TwitterApi struct for that user. The TwitterApi struct can be used for accessing any of the endpoints available.
func (TwitterApi) AddUserToList ¶
func (a TwitterApi) AddUserToList(screenName string, listID int64, v url.Values) (users []User, err error)
AddUserToList implements /lists/members/create.json
func (TwitterApi) BlockUserId ¶
func (*TwitterApi) ConfigureRedis ¶
func (c *TwitterApi) ConfigureRedis(host string, port int, db int)
func (TwitterApi) CreateList ¶
CreateList implements /lists/create.json
func (TwitterApi) DeleteTweet ¶
func (a TwitterApi) DeleteTweet(id int64, trimUser bool) (tweet Tweet, err error)
DeleteTweet will destroy (delete) the status (tweet) with the specified ID, assuming that the authenticated user is the author of the status (tweet). If trimUser is set to true, only the user's Id will be provided in the user object returned.
func (*TwitterApi) DisableThrottling ¶
func (c *TwitterApi) DisableThrottling()
Disable query throttling
func (*TwitterApi) EnableThrottling ¶
func (c *TwitterApi) EnableThrottling(rate time.Duration, bufferSize int64)
Enable query throttling using the tokenbucket algorithm
func (TwitterApi) Favorite ¶
func (a TwitterApi) Favorite(id int64) (rt Tweet, err error)
Favorite will favorite the status (tweet) with the specified ID. https://dev.twitter.com/docs/api/1.1/post/favorites/create
func (TwitterApi) FollowUser ¶
func (a TwitterApi) FollowUser(screenName string) (user User, err error)
FollowUserId follows the user with the specified screenname (username). This implements the /friendships/create endpoint, though the function name uses the terminology 'follow' as this is most consistent with colloquial Twitter terminology.
func (TwitterApi) FollowUserId ¶
FollowUserId follows the user with the specified userId. This implements the /friendships/create endpoint, though the function name uses the terminology 'follow' as this is most consistent with colloquial Twitter terminology.
func (TwitterApi) GetAvailableTrends ¶
func (a TwitterApi) GetAvailableTrends(v url.Values) (locations []Location, err error)
GetAvailableTrends implements /trends/available.json
func (TwitterApi) GetBlocksIds ¶
func (a TwitterApi) GetBlocksIds(v url.Values) (c Cursor, err error)
func (TwitterApi) GetBlocksList ¶
func (a TwitterApi) GetBlocksList(v url.Values) (c UserCursor, err error)
func (TwitterApi) GetClosestTrends ¶
func (a TwitterApi) GetClosestTrends(lat string, long string, v url.Values) (location Location, err error)
GetClosestTrends implements /trends/closest.json
func (*TwitterApi) GetDelay ¶
func (c *TwitterApi) GetDelay() time.Duration
func (TwitterApi) GetDirectMessages ¶
func (a TwitterApi) GetDirectMessages(v url.Values) (messages []DirectMessage, err error)
func (TwitterApi) GetDirectMessagesSent ¶
func (a TwitterApi) GetDirectMessagesSent(v url.Values) (messages []DirectMessage, err error)
func (TwitterApi) GetDirectMessagesShow ¶
func (a TwitterApi) GetDirectMessagesShow(v url.Values) (messages []DirectMessage, err error)
func (TwitterApi) GetFavorites ¶
func (a TwitterApi) GetFavorites(v url.Values) (favorites []Tweet, err error)
func (TwitterApi) GetFollowersIds ¶
func (a TwitterApi) GetFollowersIds(v url.Values) (c Cursor, err error)
func (TwitterApi) GetFollowersList ¶
func (a TwitterApi) GetFollowersList(v url.Values) (c UserCursor, err error)
func (TwitterApi) GetFollowersListAll ¶
func (a TwitterApi) GetFollowersListAll(v url.Values) (result chan FollowersPage)
Like GetFollowersList, but returns a channel instead of a cursor and pre-fetches the remaining results This channel is closed once all values have been fetched
Example ¶
Fetch a list of all followers without any need for managing cursors (Each page is automatically fetched when the previous one is read)
pages := api.GetFollowersListAll(nil) for page := range pages { //Print the current page of followers fmt.Println(page.Followers) }
Output:
func (TwitterApi) GetFollowersUser ¶
func (TwitterApi) GetFriendsIds ¶
func (a TwitterApi) GetFriendsIds(v url.Values) (c Cursor, err error)
func (TwitterApi) GetFriendsIdsAll ¶
func (a TwitterApi) GetFriendsIdsAll(v url.Values) (c Cursor, err error)
Like GetFriendsIds, but returns a channel instead of a cursor and pre-fetches the remaining results This channel is closed once all values have been fetched
func (TwitterApi) GetFriendsList ¶
func (a TwitterApi) GetFriendsList(v url.Values) (c UserCursor, err error)
func (TwitterApi) GetFriendsUser ¶
func (TwitterApi) GetFriendshipsIncoming ¶
func (a TwitterApi) GetFriendshipsIncoming(v url.Values) (c Cursor, err error)
func (TwitterApi) GetFriendshipsLookup ¶
func (a TwitterApi) GetFriendshipsLookup(v url.Values) (friendships []Friendship, err error)
func (TwitterApi) GetFriendshipsNoRetweets ¶
func (a TwitterApi) GetFriendshipsNoRetweets() (ids []int64, err error)
GetFriendshipsNoRetweets s a collection of user_ids that the currently authenticated user does not want to receive retweets from. It does not currently support the stringify_ids parameter
func (TwitterApi) GetFriendshipsOutgoing ¶
func (a TwitterApi) GetFriendshipsOutgoing(v url.Values) (c Cursor, err error)
func (TwitterApi) GetFriendshipsShow ¶
func (a TwitterApi) GetFriendshipsShow(v url.Values) (relationshipResponse RelationshipResponse, err error)
func (TwitterApi) GetHomeTimeline ¶
func (a TwitterApi) GetHomeTimeline(v url.Values) (timeline []Tweet, err error)
GetHomeTimeline returns the most recent tweets and retweets posted by the user and the users that they follow. https://dev.twitter.com/docs/api/1.1/get/statuses/home_timeline By default, include_entities is set to "true"
func (TwitterApi) GetListTweets ¶
func (TwitterApi) GetListsOwnedBy ¶
GetListsOwnedBy implements /lists/ownerships.json screen_name, count, and cursor are all optional values
func (TwitterApi) GetMentionsTimeline ¶
func (a TwitterApi) GetMentionsTimeline(v url.Values) (timeline []Tweet, err error)
func (TwitterApi) GetOEmbed ¶
func (a TwitterApi) GetOEmbed(v url.Values) (o OEmbed, err error)
No authorization on this endpoint. Its the only one.
func (TwitterApi) GetOEmbedId ¶
Calls GetOEmbed with the corresponding id. Convenience wrapper for GetOEmbed()
func (TwitterApi) GetPlaceTrends ¶
func (a TwitterApi) GetPlaceTrends(id string, exclude string, v url.Values) (trendResponse []TrendResponse, err error)
GetPlaceTrends implements /trends/place.json
func (TwitterApi) GetRetweets ¶
func (TwitterApi) GetRetweetsOfMe ¶
func (a TwitterApi) GetRetweetsOfMe(v url.Values) (tweets []Tweet, err error)
func (TwitterApi) GetSearch ¶
func (a TwitterApi) GetSearch(queryString string, v url.Values) (sr SearchResponse, err error)
Example ¶
package main import ( "fmt" "github.com/ChimeraCoder/anaconda" ) func main() { anaconda.SetConsumerKey("your-consumer-key") anaconda.SetConsumerSecret("your-consumer-secret") api := anaconda.NewTwitterApi("your-access-token", "your-access-token-secret") search_result, err := api.GetSearch("golang", nil) if err != nil { panic(err) } for _, tweet := range search_result.Statuses { fmt.Print(tweet.Text) } }
Output:
func (TwitterApi) GetSelf ¶
func (a TwitterApi) GetSelf(v url.Values) (u User, err error)
Get the user object for the authenticated user. Requests /account/verify_credentials
func (TwitterApi) GetTweetsLookupByIds ¶
func (TwitterApi) GetUserSearch ¶
func (TwitterApi) GetUserTimeline ¶
func (a TwitterApi) GetUserTimeline(v url.Values) (timeline []Tweet, err error)
func (TwitterApi) GetUsersLookup ¶
func (TwitterApi) GetUsersLookupByIds ¶
func (TwitterApi) GetUsersShow ¶
func (TwitterApi) GetUsersShowById ¶
func (TwitterApi) PostDMToScreenName ¶
func (a TwitterApi) PostDMToScreenName(text, screenName string) (message DirectMessage, err error)
https://dev.twitter.com/docs/api/1.1/post/direct_messages/new
func (TwitterApi) PostDMToUserId ¶
func (a TwitterApi) PostDMToUserId(text string, userId int64) (message DirectMessage, err error)
https://dev.twitter.com/docs/api/1.1/post/direct_messages/new
func (TwitterApi) PublicStreamFilter ¶
func (a TwitterApi) PublicStreamFilter(v url.Values) (stream Stream)
XXX: PublicStream(Track|Follow|Locations) func is needed?
func (TwitterApi) PublicStreamFirehose ¶
func (a TwitterApi) PublicStreamFirehose(v url.Values) (stream Stream)
XXX: To use this API authority is requied. but I dont have this. I cant test.
func (TwitterApi) PublicStreamSample ¶
func (a TwitterApi) PublicStreamSample(v url.Values) (stream Stream)
func (*TwitterApi) ReturnRateLimitError ¶
func (c *TwitterApi) ReturnRateLimitError(b bool)
ReturnRateLimitError specifies behavior when the Twitter API returns a rate-limit error. If set to true, the query will fail and return the error instead of automatically queuing and retrying the query when the rate limit expires
func (TwitterApi) Retweet ¶
func (a TwitterApi) Retweet(id int64, trimUser bool) (rt Tweet, err error)
Retweet will retweet the status (tweet) with the specified ID. trimUser functions as in DeleteTweet
func (*TwitterApi) SetDelay ¶
func (c *TwitterApi) SetDelay(t time.Duration)
SetDelay will set the delay between throttled queries To turn of throttling, set it to 0 seconds
func (*TwitterApi) SetLogger ¶
func (c *TwitterApi) SetLogger(l Logger)
SetLogger sets the Logger used by the API client. The default logger is silent. BasicLogger will log to STDERR using the log package from the standard library.
func (*TwitterApi) SetScreenName ¶
func (c *TwitterApi) SetScreenName(n string)
func (TwitterApi) SiteStream ¶
func (a TwitterApi) SiteStream(v url.Values) (stream Stream)
XXX: To use this API authority is requied. but I dont have this. I cant test.
func (TwitterApi) UnblockUser ¶
func (TwitterApi) UnblockUserId ¶
func (TwitterApi) Unfavorite ¶
func (a TwitterApi) Unfavorite(id int64) (rt Tweet, err error)
Un-favorites the status specified in the ID parameter as the authenticating user. Returns the un-favorited status in the requested format when successful. https://dev.twitter.com/docs/api/1.1/post/favorites/destroy
func (TwitterApi) UnfollowUser ¶
func (a TwitterApi) UnfollowUser(screenname string) (u User, err error)
UnfollowUser unfollows the user with the specified screenname (username) This implements the /friendships/destroy endpoint, though the function name uses the terminology 'unfollow' as this is most consistent with colloquial Twitter terminology.
func (TwitterApi) UnfollowUserId ¶
func (a TwitterApi) UnfollowUserId(userId int64) (u User, err error)
UnfollowUserId unfollows the user with the specified userId. This implements the /friendships/destroy endpoint, though the function name uses the terminology 'unfollow' as this is most consistent with colloquial Twitter terminology.
func (TwitterApi) UploadMedia ¶
func (a TwitterApi) UploadMedia(base64String string) (media Media, err error)
func (TwitterApi) UserStream ¶
func (a TwitterApi) UserStream(v url.Values) (stream Stream)
func (TwitterApi) VerifyCredentials ¶
func (a TwitterApi) VerifyCredentials() (ok bool, err error)
Verify the credentials by making a very small request
type TwitterError ¶
TwitterError represents a single Twitter error messages/code pair
func (TwitterError) Error ¶
func (te TwitterError) Error() string
type TwitterErrorResponse ¶
type TwitterErrorResponse struct {
Errors []TwitterError `json:"errors"`
}
TwitterErrorResponse has an array of Twitter error messages It satisfies the "error" interface For the most part, Twitter seems to return only a single error message Currently, we assume that this always contains exactly one error message
func (TwitterErrorResponse) Error ¶
func (tr TwitterErrorResponse) Error() string
func (TwitterErrorResponse) First ¶
func (tr TwitterErrorResponse) First() error
type User ¶
type User struct { ContributorsEnabled bool `json:"contributors_enabled"` CreatedAt string `json:"created_at"` DefaultProfile bool `json:"default_profile"` DefaultProfileImage bool `json:"default_profile_image"` Description string `json:"description"` Entities Entities `json:"entities"` FavouritesCount int `json:"favourites_count"` FollowRequestSent bool `json:"follow_request_sent"` FollowersCount int `json:"followers_count"` Following bool `json:"following"` FriendsCount int `json:"friends_count"` GeoEnabled bool `json:"geo_enabled"` Id int64 `json:"id"` IdStr string `json:"id_str"` IsTranslator bool `json:"is_translator"` Lang string `json:"lang"` // BCP-47 code of user defined language ListedCount int64 `json:"listed_count"` Location string `json:"location"` // User defined location Name string `json:"name"` Notifications bool `json:"notifications"` ProfileBackgroundColor string `json:"profile_background_color"` ProfileBackgroundImageURL string `json:"profile_background_image_url"` ProfileBackgroundImageUrlHttps string `json:"profile_background_image_url_https"` ProfileBackgroundTile bool `json:"profile_background_tile"` ProfileBannerURL string `json:"profile_banner_url"` ProfileImageURL string `json:"profile_image_url"` ProfileImageUrlHttps string `json:"profile_image_url_https"` ProfileLinkColor string `json:"profile_link_color"` ProfileSidebarBorderColor string `json:"profile_sidebar_border_color"` ProfileSidebarFillColor string `json:"profile_sidebar_fill_color"` ProfileTextColor string `json:"profile_text_color"` ProfileUseBackgroundImage bool `json:"profile_use_background_image"` Protected bool `json:"protected"` ScreenName string `json:"screen_name"` ShowAllInlineMedia bool `json:"show_all_inline_media"` Status *Tweet `json:"status"` // Only included if the user is a friend StatusesCount int64 `json:"statuses_count"` TimeZone string `json:"time_zone"` URL string `json:"url"` // From UTC in seconds UtcOffset int `json:"utc_offset"` Verified bool `json:"verified"` WithheldInCountries string `json:"withheld_in_countries"` WithheldScope string `json:"withheld_scope"` }