package main import ( "flag" "github.com/dghubble/go-twitter/twitter" "github.com/dghubble/oauth1" ) 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") ) 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 }