/
main.go
68 lines (55 loc) · 1.55 KB
/
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"context"
"encoding/json"
"flag"
"fmt"
"log"
"net/http"
twitter "github.com/0xCucu/go-twitter/v2"
)
type authorize struct {
Token string
}
func (a authorize) Add(req *http.Request) {
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", a.Token))
}
/*
*
In order to run, the user will need to provide the bearer token and the list of tweet ids.
*
*/
func main() {
token := flag.String("token", "", "twitter API token")
userID := flag.String("user_id", "", "user id")
flag.Parse()
client := &twitter.Client{
Authorizer: authorize{
Token: *token,
},
Client: http.DefaultClient,
Host: "https://api.twitter.com",
}
opts := twitter.UserMentionTimelineOpts{
TweetFields: []twitter.TweetField{twitter.TweetFieldCreatedAt, twitter.TweetFieldAuthorID, twitter.TweetFieldConversationID, twitter.TweetFieldPublicMetrics, twitter.TweetFieldContextAnnotations},
UserFields: []twitter.UserField{twitter.UserFieldUserName},
Expansions: []twitter.Expansion{twitter.ExpansionAuthorID},
MaxResults: 5,
}
fmt.Println("Callout to tweet user mention timeline callout")
timeline, err := client.UserMentionTimeline(context.Background(), *userID, opts)
if err != nil {
log.Panicf("user mention timeline error: %v", err)
}
dictionaries := timeline.Raw.TweetDictionaries()
enc, err := json.MarshalIndent(dictionaries, "", " ")
if err != nil {
log.Panic(err)
}
fmt.Println(string(enc))
metaBytes, err := json.MarshalIndent(timeline.Meta, "", " ")
if err != nil {
log.Panic(err)
}
fmt.Println(string(metaBytes))
}