(pds string, token string, uri string, depth int, parentHeight int)
| 878 | } |
| 879 | |
| 880 | func GetPost(pds string, token string, uri string, depth int, parentHeight int) (*ThreadRoot, error) { |
| 881 | // Example URL at://did:plc:dqibjxtqfn6hydazpetzr2w4/app.bsky.feed.post/3lchbospvbc2j |
| 882 | |
| 883 | url := pds + "/xrpc/app.bsky.feed.getPostThread?depth=" + fmt.Sprintf("%d", depth) + "&parentHeight=" + fmt.Sprintf("%d", parentHeight) + "&uri=" + uri |
| 884 | |
| 885 | resp, err := SendRequest(&token, http.MethodGet, url, nil) |
| 886 | if err != nil { |
| 887 | return nil, err |
| 888 | } |
| 889 | defer resp.Body.Close() |
| 890 | |
| 891 | // // Print the response body |
| 892 | // bodyBytes, _ := io.ReadAll(resp.Body) |
| 893 | // bodyString := string(bodyBytes) |
| 894 | // fmt.Println("Response Body:", bodyString) |
| 895 | |
| 896 | if resp.StatusCode != http.StatusOK { |
| 897 | bodyBytes, _ := io.ReadAll(resp.Body) |
| 898 | bodyString := string(bodyBytes) |
| 899 | fmt.Println("Response Status:", resp.StatusCode) |
| 900 | fmt.Println("Response Body:", bodyString) |
| 901 | return nil, errors.New(bodyString) // return response |
| 902 | } |
| 903 | |
| 904 | thread := ThreadRoot{} |
| 905 | if err := json.NewDecoder(resp.Body).Decode(&thread); err != nil { |
| 906 | return nil, err |
| 907 | } |
| 908 | |
| 909 | return &thread, nil |
| 910 | } |
| 911 | |
| 912 | // https://docs.bsky.app/docs/api/app-bsky-feed-get-posts |
| 913 | func GetPosts(pds string, token string, items []string) ([]*Post, error) { |
no test coverage detected