-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
71 lines (60 loc) · 1.62 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
69
70
71
package main
import (
lexutil "github.com/bluesky-social/indigo/lex/util"
"context"
"fmt"
"github.com/bluesky-social/indigo/api/atproto"
"github.com/bluesky-social/indigo/api/bsky"
"github.com/bluesky-social/indigo/util"
"github.com/bluesky-social/indigo/xrpc"
"time"
)
func main() {
// クライアントを作成
client := &xrpc.Client{
Host: "https://bsky.social",
}
// 認証
actor := "dummy.bsky.social" // ここに自分の ID を入れる
pw := "dummy" // ここに自分のパスワードを入れる
input := &atproto.ServerCreateSession_Input{
Identifier: actor,
Password: pw,
}
ctx := context.Background()
output, err := atproto.ServerCreateSession(ctx, client, input) // ここで Bearer トークンが取得できる
if err != nil {
panic(err)
}
client.Auth = &xrpc.AuthInfo{
AccessJwt: output.AccessJwt,
RefreshJwt: output.RefreshJwt,
Handle: output.Handle,
Did: output.Did,
}
// 投稿を作成
inp := &atproto.RepoCreateRecord_Input{
Collection: "app.bsky.feed.post",
Repo: client.Auth.Did,
Record: &lexutil.LexiconTypeDecoder{
&bsky.FeedPost{
Text: "Hello, World!",
CreatedAt: time.Now().Format(util.ISO8601),
Langs: []string{"ja"},
},
},
}
res, err := atproto.RepoCreateRecord(ctx, client, inp)
if err != nil {
panic(err)
}
fmt.Println(res.Uri)
// actor (自分) のフィードを新しい順に 10 件取得
feed, err := bsky.FeedGetAuthorFeed(ctx, client, actor, "", "", 10)
if err != nil {
panic(err)
}
for _, f := range feed.Feed {
fmt.Printf("%s\n", f.Post.Record.Val.(*bsky.FeedPost).Text)
}
}