forked from ChimeraCoder/anaconda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_test.go
62 lines (52 loc) · 1.65 KB
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package anaconda_test
import (
"fmt"
"time"
"github.com/ChimeraCoder/anaconda"
)
// Initialize an client library for a given user.
// This only needs to be done *once* per user
func ExampleTwitterApi_InitializeClient() {
anaconda.SetConsumerKey("your-consumer-key")
anaconda.SetConsumerSecret("your-consumer-secret")
api := anaconda.NewTwitterApi(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
fmt.Println(*api.Credentials)
}
func ExampleTwitterApi_GetSearch() {
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)
}
}
// Throttling queries can easily be handled in the background, automatically
func ExampleTwitterApi_Throttling() {
api := anaconda.NewTwitterApi("your-access-token", "your-access-token-secret")
api.EnableThrottling(10*time.Second, 5)
// These queries will execute in order
// with appropriate delays inserted only if necessary
golangTweets, err := api.GetSearch("golang", nil)
anacondaTweets, err2 := api.GetSearch("anaconda", nil)
if err != nil {
panic(err)
}
if err2 != nil {
panic(err)
}
fmt.Println(golangTweets)
fmt.Println(anacondaTweets)
}
// Fetch a list of all followers without any need for managing cursors
// (Each page is automatically fetched when the previous one is read)
func ExampleTwitterApi_GetFollowersListAll() {
pages := api.GetFollowersListAll(nil)
for page := range pages {
//Print the current page of followers
fmt.Println(page.Followers)
}
}