• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

json/H26-Feb-2018-

vendor/github.com/H26-Feb-2018-

.appveyor.ymlH A D26-Feb-2018164

.gitignoreH A D26-Feb-201848

.travis.ymlH A D26-Feb-20181 KiB

COPYINGH A D26-Feb-20181.1 KiB

Gopkg.lockH A D26-Feb-20181 KiB

Gopkg.tomlH A D26-Feb-2018844

LICENSEH A D26-Feb-20181.1 KiB

READMEH A D26-Feb-20184.6 KiB

README.mdH A D26-Feb-20184.6 KiB

account.goH A D26-Feb-2018619

backoff.goH A D26-Feb-20181.4 KiB

blocks.goH A D26-Feb-20181.6 KiB

configuration.goH A D26-Feb-20181,008

directmessage.goH A D26-Feb-2018593

directmessages.goH A D26-Feb-20182.3 KiB

errors.goH A D26-Feb-20183.1 KiB

example_test.goH A D26-Feb-20181.6 KiB

favorites.goH A D26-Feb-2018291

friends_followers.goH A D26-Feb-20189.1 KiB

geosearch.goH A D26-Feb-20181.8 KiB

list.goH A D26-Feb-2018763

lists.goH A D26-Feb-20183.1 KiB

log.goH A D26-Feb-20183.8 KiB

media.goH A D26-Feb-20182.5 KiB

mutes.goH A D26-Feb-20181.6 KiB

oembed.goH A D26-Feb-20181.2 KiB

oembed_test.goH A D26-Feb-20181.6 KiB

place.goH A D26-Feb-20181.1 KiB

rate_limit_status.goH A D26-Feb-2018853

relationship.goH A D26-Feb-20181.1 KiB

search.goH A D26-Feb-20181.6 KiB

streaming.goH A D26-Feb-20188.6 KiB

timeline.goH A D26-Feb-20182.2 KiB

trends.goH A D26-Feb-20182.2 KiB

tweet.goH A D26-Feb-20185.9 KiB

tweets.goH A D26-Feb-20184 KiB

twitter.goH A D26-Feb-201811.7 KiB

twitter_entities.goH A D26-Feb-20182.2 KiB

twitter_test.goH A D26-Feb-201812.6 KiB

twitter_user.goH A D26-Feb-20183.3 KiB

users.goH A D26-Feb-20183.2 KiB

webhook.goH A D26-Feb-20184.1 KiB

README

1Anaconda
2====================
3
4[![Build Status](https://travis-ci.org/ChimeraCoder/anaconda.svg?branch=master)](https://travis-ci.org/ChimeraCoder/anaconda) [![Build Status](https://ci.appveyor.com/api/projects/status/63pi6csod8bps80i/branch/master?svg=true)](https://ci.appveyor.com/project/ChimeraCoder/anaconda/branch/master) [![GoDoc](https://godoc.org/github.com/ChimeraCoder/anaconda?status.svg)](https://godoc.org/github.com/ChimeraCoder/anaconda)
5
6Anaconda is a simple, transparent Go package for accessing version 1.1 of the Twitter API.
7
8Successful API queries return native Go structs that can be used immediately, with no need for type assertions.
9
10
11
12Examples
13-------------
14
15### Authentication
16
17If 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:
18
19````go
20api := anaconda.NewTwitterApiWithCredentials("your-access-token", "your-access-token-secret", "your-consumer-key", "your-consumer-secret")
21````
22
23### Queries
24
25Queries are conducted using a pointer to an authenticated `TwitterApi` struct. In v1.1 of Twitter's API, all requests should be authenticated.
26
27````go
28searchResult, _ := api.GetSearch("golang", nil)
29for _ , tweet := range searchResult.Statuses {
30    fmt.Println(tweet.Text)
31}
32````
33Certain endpoints allow separate optional parameter; if desired, these can be passed as the final parameter.
34
35````go
36//Perhaps we want 30 values instead of the default 15
37v := url.Values{}
38v.Set("count", "30")
39result, err := api.GetSearch("golang", v)
40````
41
42(Remember that `url.Values` is equivalent to a `map[string][]string`, if you find that more convenient notation when specifying values). Otherwise, `nil` suffices.
43
44
45
46Endpoints
47------------
48
49Anaconda implements most of the endpoints defined in the [Twitter API documentation](https://developer.twitter.com/en/docs). 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`).
50
51In a few cases, a shortened form has been chosen to make life easier (for example, retweeting is simply the function `Retweet`)
52
53
54
55Error Handling, Rate Limiting, and Throttling
56---------------------------------
57
58### Error Handling
59
60Twitter 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.
61
62
63If you make queries too quickly, you may bump against Twitter's [rate limits](https://developer.twitter.com/en/docs/basics/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.
64
65In 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).
66
67
68(If desired, this feature can be turned off by calling `ReturnRateLimitError(true)`.)
69
70
71### Throttling
72
73Anaconda now supports automatic client-side throttling of queries to avoid hitting the Twitter rate-limit.
74
75This is currently *off* by default; however, it may be turned on by default in future versions of the library, as the implementation is improved.
76
77
78To set a delay between queries, use the `SetDelay` method:
79
80````go
81    api.SetDelay(10 * time.Second)
82````
83
84Delays are set specific to each `TwitterApi` struct, so queries that use different users' access credentials are completely independent.
85
86
87To turn off automatic throttling, set the delay to `0`:
88
89````go
90    api.SetDelay(0 * time.Second)
91````
92
93### Query Queue Persistence
94
95If 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.
96
97### Google App Engine
98
99Since Google App Engine doesn't make the standard `http.Transport` available, it's necessary to tell Anaconda to use a different client context.
100
101````go
102	api = anaconda.NewTwitterApi("", "")
103	c := appengine.NewContext(r)
104	api.HttpClient.Transport = &urlfetch.Transport{Context: c}
105````
106
107
108License
109-----------
110Anaconda is free software licensed under the MIT/X11 license. Details provided in the LICENSE file.
111

README.md

1Anaconda
2====================
3
4[![Build Status](https://travis-ci.org/ChimeraCoder/anaconda.svg?branch=master)](https://travis-ci.org/ChimeraCoder/anaconda) [![Build Status](https://ci.appveyor.com/api/projects/status/63pi6csod8bps80i/branch/master?svg=true)](https://ci.appveyor.com/project/ChimeraCoder/anaconda/branch/master) [![GoDoc](https://godoc.org/github.com/ChimeraCoder/anaconda?status.svg)](https://godoc.org/github.com/ChimeraCoder/anaconda)
5
6Anaconda is a simple, transparent Go package for accessing version 1.1 of the Twitter API.
7
8Successful API queries return native Go structs that can be used immediately, with no need for type assertions.
9
10
11
12Examples
13-------------
14
15### Authentication
16
17If 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:
18
19````go
20api := anaconda.NewTwitterApiWithCredentials("your-access-token", "your-access-token-secret", "your-consumer-key", "your-consumer-secret")
21````
22
23### Queries
24
25Queries are conducted using a pointer to an authenticated `TwitterApi` struct. In v1.1 of Twitter's API, all requests should be authenticated.
26
27````go
28searchResult, _ := api.GetSearch("golang", nil)
29for _ , tweet := range searchResult.Statuses {
30    fmt.Println(tweet.Text)
31}
32````
33Certain endpoints allow separate optional parameter; if desired, these can be passed as the final parameter.
34
35````go
36//Perhaps we want 30 values instead of the default 15
37v := url.Values{}
38v.Set("count", "30")
39result, err := api.GetSearch("golang", v)
40````
41
42(Remember that `url.Values` is equivalent to a `map[string][]string`, if you find that more convenient notation when specifying values). Otherwise, `nil` suffices.
43
44
45
46Endpoints
47------------
48
49Anaconda implements most of the endpoints defined in the [Twitter API documentation](https://developer.twitter.com/en/docs). 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`).
50
51In a few cases, a shortened form has been chosen to make life easier (for example, retweeting is simply the function `Retweet`)
52
53
54
55Error Handling, Rate Limiting, and Throttling
56---------------------------------
57
58### Error Handling
59
60Twitter 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.
61
62
63If you make queries too quickly, you may bump against Twitter's [rate limits](https://developer.twitter.com/en/docs/basics/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.
64
65In 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).
66
67
68(If desired, this feature can be turned off by calling `ReturnRateLimitError(true)`.)
69
70
71### Throttling
72
73Anaconda now supports automatic client-side throttling of queries to avoid hitting the Twitter rate-limit.
74
75This is currently *off* by default; however, it may be turned on by default in future versions of the library, as the implementation is improved.
76
77
78To set a delay between queries, use the `SetDelay` method:
79
80````go
81    api.SetDelay(10 * time.Second)
82````
83
84Delays are set specific to each `TwitterApi` struct, so queries that use different users' access credentials are completely independent.
85
86
87To turn off automatic throttling, set the delay to `0`:
88
89````go
90    api.SetDelay(0 * time.Second)
91````
92
93### Query Queue Persistence
94
95If 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.
96
97### Google App Engine
98
99Since Google App Engine doesn't make the standard `http.Transport` available, it's necessary to tell Anaconda to use a different client context.
100
101````go
102	api = anaconda.NewTwitterApi("", "")
103	c := appengine.NewContext(r)
104	api.HttpClient.Transport = &urlfetch.Transport{Context: c}
105````
106
107
108License
109-----------
110Anaconda is free software licensed under the MIT/X11 license. Details provided in the LICENSE file.
111