mi-v1/cmd/mi/twitter.go

34 lines
946 B
Go
Raw Normal View History

2020-01-11 18:38:50 +00:00
package main
import (
2020-01-11 19:11:30 +00:00
"flag"
2020-01-11 18:38:50 +00:00
"github.com/dghubble/go-twitter/twitter"
"github.com/dghubble/oauth1"
)
2020-01-11 19:11:30 +00:00
var (
// Twitter
twitterAPIKey = flag.String("twitter-api-key", "", "Twitter API key")
twitterAPISecret = flag.String("twitter-api-secret", "", "Twitter API secret")
twitterConsumerToken = flag.String("twitter-consumer-token", "", "Twitter consumer Token")
twitterConsumerSecret = flag.String("twitter-consumer-secret", "", "Twitter consumer Secret")
)
2020-01-11 18:38:50 +00:00
func makeTwitter() (*twitter.Client, error) {
config := oauth1.NewConfig(*twitterConsumerToken, *twitterConsumerSecret)
token := oauth1.NewToken(*twitterAPIKey, *twitterAPISecret)
// http.Client will automatically authorize Requests
httpClient := config.Client(oauth1.NoContext, token)
// twitter client
client := twitter.NewClient(httpClient)
_, _, err := client.Accounts.VerifyCredentials(nil)
if err != nil {
return nil, err
}
return client, nil
}