Anaconda is a simple, transparent Go package 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.
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 are conducted using the authenticated TwitterApi
struct. In v1.1 of Twitter's API, all requests should be authenticated.
searchResult, _ := api.GetSearch("golang", nil)
for _ , tweet := range searchResult {
fmt.Println(tweet.Text)
}
Certain endpoints allow separate optional parameter; if desired, these can be passed as the final parameter.
//Perhaps we want 30 values instead of the default 15
v := url.Values{}
v.Set("count", "30")
result, err := api.GetSearch("golang", v)
(Remember that url.Values
is equivalent to a map[string][]string
, if you find that more convenient notation when specifying values). Otherwise, nil
suffices.
Anaconda implements most of the endpoints defined in the Twitter API documentation. 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
)
Anaconda is free software licensed under the MIT/X11 license. Details provided in the LICENSE file.