All Projects → ChimeraCoder → Anaconda

ChimeraCoder / Anaconda

Licence: other
A Go client library for the Twitter 1.1 API

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Anaconda

Twitter
Twitter API for Laravel 5.5+, 6.x, 7.x & 8.x
Stars: ✭ 755 (-29.9%)
Mutual labels:  api-client, twitter
Mastodon Bridge
Moved to https://source.joinmastodon.org/mastodon/bridge
Stars: ✭ 53 (-95.08%)
Mutual labels:  twitter
Slack Twitter
Read your timeline, fave tweets, and post to Twitter from Slack.
Stars: ✭ 47 (-95.64%)
Mutual labels:  twitter
Metrotwitter
What Twitter reveals about the differences between cities and the monoculture of the Bay Area
Stars: ✭ 52 (-95.17%)
Mutual labels:  twitter
App Search Php
Elastic App Search Official PHP Client
Stars: ✭ 48 (-95.54%)
Mutual labels:  api-client
Keyring
Keyring is an authentication framework for WordPress. It comes with definitions for a variety of HTTP Basic, OAuth1 and OAuth2 web services. Use it as a common foundation for working with other web services from within WordPress code.
Stars: ✭ 52 (-95.17%)
Mutual labels:  twitter
Twitter Follow Exploit
Automated Twitter mass account creation and follow using Selenium and Tor VPN
Stars: ✭ 47 (-95.64%)
Mutual labels:  twitter
Simple Salesforce
A very simple Salesforce.com REST API client for Python
Stars: ✭ 1,072 (-0.46%)
Mutual labels:  api-client
Cryptocurrency Dashboard
Crypto Currency Dashboard Using Twitter 🐦 And Coinmarketcap 🚀 API
Stars: ✭ 54 (-94.99%)
Mutual labels:  twitter
Php Quandl
Easy access to the Quandl Data API using PHP
Stars: ✭ 51 (-95.26%)
Mutual labels:  api-client
Apiclientcodegen
A collection of Visual Studio custom tool code generators for Swagger / OpenAPI specification files
Stars: ✭ 50 (-95.36%)
Mutual labels:  api-client
Streamingclientlibrary
C# client library for Twitch, YouTube Live, and other streaming services
Stars: ✭ 48 (-95.54%)
Mutual labels:  api-client
Google Measurement Php Client
PHP Client to send analytics data over the Google Measurement Protocol to Google Analytics
Stars: ✭ 52 (-95.17%)
Mutual labels:  api-client
Stocksight
Stock market analyzer and predictor using Elasticsearch, Twitter, News headlines and Python natural language processing and sentiment analysis
Stars: ✭ 1,037 (-3.71%)
Mutual labels:  twitter
Yelp Android
Stars: ✭ 53 (-95.08%)
Mutual labels:  api-client
Laravel5 Genderize Api Client
Laravel 5 client for the Genderize.io API
Stars: ✭ 47 (-95.64%)
Mutual labels:  api-client
Devrant
Unofficial wrapper for the public devRant API.
Stars: ✭ 48 (-95.54%)
Mutual labels:  api-client
Alphavantage.net
.Net client library for Alpha Vantage API
Stars: ✭ 52 (-95.17%)
Mutual labels:  api-client
Wikipedir
R's MediaWiki API client library
Stars: ✭ 54 (-94.99%)
Mutual labels:  api-client
Imageviewer.swift
An easy to use Image Viewer that is inspired by Facebook
Stars: ✭ 1,071 (-0.56%)
Mutual labels:  twitter

Anaconda

Build Status Build Status GoDoc

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.

Examples

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:

api := anaconda.NewTwitterApiWithCredentials("your-access-token", "your-access-token-secret", "your-consumer-key", "your-consumer-secret")

Queries

Queries are conducted using a pointer to an authenticated TwitterApi struct. In v1.1 of Twitter's API, all requests should be authenticated.

searchResult, _ := api.GetSearch("golang", nil)
for _ , tweet := range searchResult.Statuses {
    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.

Streaming

Anaconda supports the Streaming APIs. You can use PublicStream* or UserStream API methods. A go loop is started an gives you an stream that sends interface{} objects through it's chan C Objects which you can cast into a tweet, event and more.

v := url.Values{}
s := api.UserStream(v)

for t := range s.C {
  switch v := t.(type) {
  case anaconda.Tweet:
    fmt.Printf("%-15s: %s\n", v.User.ScreenName, v.Text)
  case anaconda.EventTweet:
    switch v.Event.Event {
    case "favorite":
      sn := v.Source.ScreenName
      tw := v.TargetObject.Text
      fmt.Printf("Favorited by %-15s: %s\n", sn, tw)
    case "unfavorite":
      sn := v.Source.ScreenName
      tw := v.TargetObject.Text
      fmt.Printf("UnFavorited by %-15s: %s\n", sn, tw)
    }
  }
}

Endpoints

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)

Error Handling, Rate Limiting, and Throttling

Error Handling

Twitter errors are returned as an ApiError, which satisfies the error interface and can be treated as a vanilla error. However, it also contains the additional information returned by the Twitter API that may be useful in deciding how to proceed after encountering an error.

If you make queries too quickly, you may bump against Twitter's rate limits. If this happens, anaconda automatically retries the query when the rate limit resets, using the X-Rate-Limit-Reset header that Twitter provides to determine how long to wait.

In other words, users of the anaconda library should not need to handle rate limiting errors themselves; this is handled seamlessly behind-the-scenes. If an error is returned by a function, another form of error must have occurred (which can be checked by using the fields provided by the ApiError struct).

(If desired, this feature can be turned off by calling ReturnRateLimitError(true).)

Throttling

Anaconda now supports automatic client-side throttling of queries to avoid hitting the Twitter rate-limit.

This is currently off by default; however, it may be turned on by default in future versions of the library, as the implementation is improved.

To set a delay between queries, use the SetDelay method:

api.SetDelay(10 * time.Second)

Delays are set specific to each TwitterApi struct, so queries that use different users' access credentials are completely independent.

To turn off automatic throttling, set the delay to 0:

api.SetDelay(0 * time.Second)

Query Queue Persistence

If your code creates a NewTwitterApi in a regularly called function, you'll need to call .Close() on the API struct to clear the queryQueue and allow the goroutine to exit. Otherwise you could see goroutine and therefor heap memory leaks in long-running applications.

Google App Engine

Since Google App Engine doesn't make the standard http.Transport available, it's necessary to tell Anaconda to use a different client context.

api = anaconda.NewTwitterApi("", "")
c := appengine.NewContext(r)
api.HttpClient.Transport = &urlfetch.Transport{Context: c}

License

Anaconda is free software licensed under the MIT/X11 license. Details provided in the LICENSE file.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].