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 { 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 ¶
- func AuthorizationURL(callback string) (string, *oauth.Credentials, error)
- func GetCredentials(tempCred *oauth.Credentials, verifier string) (*oauth.Credentials, url.Values, error)
- func SetConsumerKey(consumer_key string)
- func SetConsumerSecret(consumer_secret string)
- type Cursor
- type DirectMessage
- type Friendship
- type Retweet
- type Tweet
- type TwitterApi
- func (a TwitterApi) DeleteTweet(id int64, trimUser bool) (tweet Tweet, err error)
- 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) GetFollowersIds(v url.Values) (c Cursor, err error)
- func (a TwitterApi) GetFollowersList(v url.Values) (c TwitterUserCursor, err error)
- func (a TwitterApi) GetFriendsIds(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) GetHomeTimeline() (timeline []Tweet, err error)
- func (a TwitterApi) GetMentionsTimeline(v url.Values) (timeline []Tweet, 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(query string, v url.Values) (timeline []Tweet, err error)
- func (a TwitterApi) GetTweet(id int64, v url.Values) (tweet Tweet, err error)
- func (a TwitterApi) GetUserTimeline(v url.Values) (timeline []Tweet, err error)
- func (a TwitterApi) GetUsersLookup(usernames string, v url.Values) (u []TwitterUser, err error)
- func (a TwitterApi) GetUsersLookupByIds(ids []int64, v url.Values) (u []TwitterUser, err error)
- func (a TwitterApi) PostTweet(status string, v url.Values) (tweet Tweet, err error)
- func (a TwitterApi) Retweet(id int64, trimUser bool) (rt Retweet, err error)
- type TwitterEntities
- type TwitterUser
- type TwitterUserCursor
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AuthorizationURL ¶
func AuthorizationURL(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(tempCred *oauth.Credentials, verifier string) (*oauth.Credentials, url.Values, error)
func SetConsumerKey ¶
func SetConsumerKey(consumer_key string)
SetConsumerKey will set the application-specific consumer_key used in the initial OAuth process This key is listed on https://dev.twitter.com/apps/YOUR_APP_ID/show
func SetConsumerSecret ¶
func SetConsumerSecret(consumer_secret string)
SetConsumerSecret will set the application-specific secret used in the initial OAuth process This secret is listed on https://dev.twitter.com/apps/YOUR_APP_ID/show
Types ¶
type DirectMessage ¶
type DirectMessage struct { Sender struct { Screen_name string // contains filtered or unexported fields } // contains filtered or unexported fields }
type Friendship ¶
type Retweet ¶
type Retweet struct { Favorited *bool User TwitterUser Truncated *bool Text *string Retweet_count *float64 Entities struct { Urls []interface{} Hashtags []interface{} User_mentions []interface{} } Retweeted_status struct { Favorited *bool User TwitterUser Truncated *bool Text *string Retweet_count *float64 Entities struct { Hashtags []interface{} User_mentions []interface{} Urls []interface{} } Id_str *string Created_at *string Source *string Id *float64 Retweeted *bool } Id_str *string Created_at *string Source *string Id *float64 Retweeted *bool }
type TwitterApi ¶
type TwitterApi struct {
Credentials *oauth.Credentials
}
func NewTwitterApi ¶
func NewTwitterApi(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) 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) 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) GetFollowersIds ¶
func (a TwitterApi) GetFollowersIds(v url.Values) (c Cursor, err error)
func (TwitterApi) GetFollowersList ¶
func (a TwitterApi) GetFollowersList(v url.Values) (c TwitterUserCursor, err error)
func (TwitterApi) GetFriendsIds ¶
func (a TwitterApi) GetFriendsIds(v url.Values) (c Cursor, err error)
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 returns 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) GetHomeTimeline ¶
func (a TwitterApi) GetHomeTimeline() (timeline []Tweet, err error)
func (TwitterApi) GetMentionsTimeline ¶
func (a TwitterApi) GetMentionsTimeline(v url.Values) (timeline []Tweet, err error)
func (TwitterApi) GetRetweets ¶
func (TwitterApi) GetRetweetsOfMe ¶
func (a TwitterApi) GetRetweetsOfMe(v url.Values) (tweets []Tweet, err error)
func (TwitterApi) GetSearch ¶
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 { fmt.Print(tweet.Text) } }
Output:
func (TwitterApi) GetUserTimeline ¶
func (a TwitterApi) GetUserTimeline(v url.Values) (timeline []Tweet, err error)
func (TwitterApi) GetUsersLookup ¶
func (a TwitterApi) GetUsersLookup(usernames string, v url.Values) (u []TwitterUser, err error)
func (TwitterApi) GetUsersLookupByIds ¶
func (a TwitterApi) GetUsersLookupByIds(ids []int64, v url.Values) (u []TwitterUser, err error)
type TwitterEntities ¶
type TwitterUser ¶
type TwitterUser struct { Statuses_count *int64 Contributors_enabled *bool Friends_count *int64 Geo_enabled *bool Description *string Screen_name *string Listed_count *int64 Followers_count *int64 Location *string Profile_background_image_url *string Name *string Default_profile_image *bool Profile_image_url_https *string Notifications *bool Protected *bool Id_str *string Profile_background_color *string Created_at *string Default_profile *bool Url *string Id *int64 Verified *bool Profile_link_color *string Profile_image_url *string Profile_use_background_image *bool Favourites_count *int64 Profile_background_image_url_https *string Is_translator *bool Follow_request_sent *bool Following *bool Profile_background_tile *bool Show_all_inline_media *bool Profile_text_color *string Lang *string Entities *TwitterEntities }
type TwitterUserCursor ¶
type TwitterUserCursor struct { Previous_cursor int64 Previous_cursor_str string Next_cursor int64 Next_cursor_str string Users []TwitterUser }