fixed Get on post service
This commit is contained in:
@@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -25,11 +26,20 @@ func run() (err error) {
|
|||||||
|
|
||||||
client.OnRequestCompleted(logResponse)
|
client.OnRequestCompleted(logResponse)
|
||||||
|
|
||||||
client.Subreddit.Search(ctx, "programming", nil)
|
posts, _, err := client.Subreddit.HotPosts(ctx, "golang", &reddit.ListOptions{Limit: 5})
|
||||||
client.Subreddit.SearchNames(ctx, "monitor")
|
if err != nil {
|
||||||
client.Subreddit.SearchPosts(ctx, "react", "webdev", nil)
|
log.Fatal("Could not get hot posts:", err)
|
||||||
client.Subreddit.HotPosts(ctx, "golang", &reddit.ListOptions{Limit: 5})
|
}
|
||||||
|
if len(posts) == 0 {
|
||||||
|
log.Fatal("No posts")
|
||||||
|
}
|
||||||
|
details, resp, err := client.Post.Get(ctx, posts[0].ID, posts[0].SubredditName)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Could not get post details: Status code ", resp.Status)
|
||||||
|
}
|
||||||
|
b, _ := json.MarshalIndent(details, "", " ")
|
||||||
|
log.Println("Got post details")
|
||||||
|
log.Println(string(b))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -65,8 +65,8 @@ type SubmitLinkRequest struct {
|
|||||||
// Get a post with its comments.
|
// Get a post with its comments.
|
||||||
// id is the ID36 of the post, not its full id.
|
// id is the ID36 of the post, not its full id.
|
||||||
// Example: instead of t3_abc123, use abc123.
|
// Example: instead of t3_abc123, use abc123.
|
||||||
func (s *PostService) Get(ctx context.Context, id string) (*PostAndComments, *Response, error) {
|
func (s *PostService) Get(ctx context.Context, id, subreddit string) (*PostAndComments, *Response, error) {
|
||||||
path := fmt.Sprintf("comments/%s", id)
|
path := fmt.Sprintf("r/%s/comments/%s/", subreddit, id)
|
||||||
req, err := s.client.NewRequest(http.MethodGet, path, nil)
|
req, err := s.client.NewRequest(http.MethodGet, path, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
|
|||||||
Reference in New Issue
Block a user