-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
42 lines (35 loc) · 1006 Bytes
/
main.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
package main
import (
"github.com/dghubble/go-twitter/twitter"
"github.com/dghubble/oauth1"
"github.com/joho/godotenv"
"log"
"os"
)
func main() {
err := godotenv.Load(".env")
if err != nil {
log.Fatalf(".env File not found")
}
config := oauth1.NewConfig(os.Getenv("API_KEY"),
os.Getenv("API_KEY_SECRET"))
token := oauth1.NewToken(os.Getenv("ACCESS_TOKEN"),
os.Getenv("ACCESS_TOKEN_SECRET"))
httpClient := config.Client(oauth1.NoContext, token)
client := twitter.NewClient(httpClient)
tweets, _, err := client.Search.Tweets(&twitter.SearchTweetParams{
Query: "#golang", // the word of phrase we want to query, note that it is case insensitive
Count: 5, // the amount of tweets to be returned
})
// check for errors and exit the program
if err != nil {
log.Fatal(err)
}
// iterates over the results and retweet every tweet
for _, tweet := range tweets.Statuses {
_, _, err := client.Statuses.Retweet(tweet.ID, nil)
if err != nil {
log.Fatal(err)
}
}
}