-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient.go
45 lines (34 loc) · 998 Bytes
/
client.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
43
44
45
package main
import (
"fmt"
"log"
"os"
"github.com/dghubble/go-twitter/twitter"
"github.com/dghubble/oauth1"
"github.com/joho/godotenv"
)
func Config() {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
fmt.Println("Error loading .env file")
}
fmt.Println("Starting Server")
apiKey := os.Getenv("API_KEY")
apiKeySecret := os.Getenv("API_KEY_SECRET")
accessToken := os.Getenv("ACCESS_TOKEN")
accessTokenSecret := os.Getenv("ACCESS_TOKEN_SECRET")
config := oauth1.NewConfig(apiKey, apiKeySecret)
token := oauth1.NewToken(accessToken, accessTokenSecret)
httpClient := config.Client(oauth1.NoContext, token)
client := twitter.NewClient(httpClient)
user, _, err := client.Accounts.VerifyCredentials(&twitter.AccountVerifyParams{})
if err != nil {
fmt.Printf("err : %v\n", err)
}
fmt.Printf("Account: @%s \n", user.ScreenName)
_, _, err = client.Statuses.Update(ConvertMoney(), nil)
if err != nil {
fmt.Printf("err : %v\n", err)
}
}