@@ -246,6 +246,12 @@ type ItemByWithDate struct {
246246 Actor User `json:"actor"`
247247}
248248
249+ type PostSearchResult struct {
250+ Posts []Post `json:"posts"`
251+ HitsTotal int `json:"hitsTotal"`
252+ Cursor string `json:"cursor"`
253+ }
254+
249255type UserSearchResult struct {
250256 Actors []User `json:"actors"`
251257}
@@ -1209,6 +1215,35 @@ func UserSearch(pds string, token string, query string) ([]User, error) {
12091215 return users .Actors , nil
12101216}
12111217
1218+ func PostSearch (pds string , token string , query string ) ([]Post , error ) {
1219+ url := pds + "/xrpc/app.bsky.feed.searchPosts?q=" + url .QueryEscape (query )
1220+
1221+ resp , err := SendRequest (& token , http .MethodGet , url , nil )
1222+ if err != nil {
1223+ return nil , err
1224+ }
1225+ defer resp .Body .Close ()
1226+
1227+ // // Print the response body
1228+ // bodyBytes, _ := io.ReadAll(resp.Body)
1229+ // bodyString := string(bodyBytes)
1230+ // fmt.Println("Response Body:", bodyString)
1231+
1232+ if resp .StatusCode != http .StatusOK {
1233+ bodyBytes , _ := io .ReadAll (resp .Body )
1234+ bodyString := string (bodyBytes )
1235+ fmt .Println ("Response Status:" , resp .StatusCode )
1236+ fmt .Println ("Response Body:" , bodyString )
1237+ return nil , errors .New ("failed to fetch search results" )
1238+ }
1239+
1240+ posts := PostSearchResult {}
1241+ if err := json .NewDecoder (resp .Body ).Decode (& posts ); err != nil {
1242+ return nil , err
1243+ }
1244+ return posts .Posts , nil
1245+ }
1246+
12121247// thank you https://docs.bsky.app/blog/create-post#replies
12131248func GetReplyRefs (pds string , token string , parentURI string ) (* ReplySubject , error ) {
12141249 // Get the parent post
0 commit comments