Skip to content

Instantly share code, notes, and snippets.

@techmaniack
Last active June 1, 2017 11:56
Show Gist options
  • Save techmaniack/b6c2eb4e549839a2eb166d1f6628d7f9 to your computer and use it in GitHub Desktop.
Save techmaniack/b6c2eb4e549839a2eb166d1f6628d7f9 to your computer and use it in GitHub Desktop.
Simple twitter bot written in Golang
package main
import (
"fmt"
"github.com/dghubble/go-twitter/twitter"
"github.com/dghubble/oauth1"
)
func main() {
consumerKey := "KEY"
consumerSecret := "SECRET"
accessToken := "TOKEN"
accessSecret := "SECRET"
config := oauth1.NewConfig(consumerKey, consumerSecret)
token := oauth1.NewToken(accessToken, accessSecret)
// OAuth1 http.Client will automatically authorize Requests
httpClient := config.Client(oauth1.NoContext, token)
// Twitter client
client := twitter.NewClient(httpClient)
// Search tweets to retweet
searchParams := &twitter.SearchTweetParams{
Query: "#golang",
Count: 5,
ResultType: "recent",
Lang: "en",
}
searchResult, _, _ := client.Search.Tweets(searchParams)
// Retweet
for _, tweet := range searchResult.Statuses {
tweet_id := tweet.ID
client.Statuses.Retweet(tweet_id, &twitter.StatusRetweetParams{})
fmt.Printf("RETWEETED: %+v\n", tweet.Text)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment