-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
38 lines (32 loc) · 1001 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
package main
import (
"context"
"fmt"
"os"
"strconv"
"github.com/coze-dev/coze-go"
)
func main() {
// Get an access_token through personal access token or oauth.
token := os.Getenv("COZE_API_TOKEN")
authCli := coze.NewTokenAuth(token)
datasetID, _ := strconv.ParseInt(os.Getenv("DATASET_ID"), 10, 64)
// Init the Coze client through the access_token.
cozeCli := coze.NewCozeAPI(authCli, coze.WithBaseURL(os.Getenv("COZE_API_BASE")))
ctx := context.Background()
// you can use iterator to automatically retrieve next page
documents, err := cozeCli.Datasets.Documents.List(ctx, &coze.ListDatasetsDocumentsReq{Size: 2, DatasetID: datasetID})
if err != nil {
fmt.Println("Error fetching documents:", err)
return
}
for documents.Next() {
fmt.Println(documents.Current())
}
if documents.Err() != nil {
fmt.Println("Error fetching documents:", documents.Err())
return
}
// the page result will return followed information
fmt.Println("has_more:", documents.HasMore())
}