// Test that creating a TwitterApi client creates a client with non-empty OAuth credentials func Test_TwitterApi_NewTwitterApi(t *testing.T) { anaconda.SetConsumerKey(CONSUMER_KEY) anaconda.SetConsumerSecret(CONSUMER_SECRET) api = anaconda.NewTwitterApi(ACCESS_TOKEN, ACCESS_TOKEN_SECRET) if api.Credentials == nil { t.Errorf("Twitter Api client has empty (nil) 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) }
// 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 init() { // Initialize api so it can be used even when invidual tests are run in isolation anaconda.SetConsumerKey(CONSUMER_KEY) anaconda.SetConsumerSecret(CONSUMER_SECRET) api = anaconda.NewTwitterApi(ACCESS_TOKEN, ACCESS_TOKEN_SECRET) }