无法使用API添加Whisper帖子

我无法通过 API 添加私信帖子。我在给定的 Go 结构体中将 Whisper 字段设置为 true

type Post struct {
    TopicID   int       `json:"topic_id"`
    Raw       string    `json:"raw"`
    CreatedAt time.Time `json:"created_at"`
    PostType  int       `json:"post_type"`
    Whisper   bool      `json:"whisper"`
}

无论是将 whisper 设置为 true 还是将 post_type 设置为 4,似乎都无法对我生效。帖子已被添加,但它不是私信。不过,我可以通过用户界面添加私信,这表明这不是权限问题。有人能帮我看看我哪里做错了吗?

1 个赞

post_type 应该是不必要的。如果它包含 topic_id,系统就知道这是一条帖子而非新话题。我使用 curl 的方式如下:

curl -i -sS -X POST "http://localhost:3000/posts.json"  \
-H "Content-Type: multipart/form-data;"  \
-H "Api-Key: 079fb2bb12d3b436bb11bde8eb58aaa9a36560fa7d79b14b3087aa40b1ebc2c4"  \
-H "Api-Username: blake.erickson"  \
-F "raw=92d2e4a938f8d2c65e3fbbcf68e4c272 374f11b3488a03d5d299e862003b09a3 76cdef8f63901f150f2bbf5579cd0b22"  \
-F "topic_id=11"  \
-F "whisper=true"

HTTP/1.1 200 OK

5 个赞

这似乎正在运行,但为什么响应中没有返回 whisper=true?相反,我在所有私信中看到 post_type=4 而不是 post_type=1,这是否意味着什么?

1 个赞

是的,这是好事。post_type=4 表示这是一条密信帖子,意味着它已成功创建。如果返回的是 post_type=1,则说明它不是密信,而只是一条普通帖子。

创建帖子的接口不允许直接传递 post_type,而是要求你指定 whisper=true

1 个赞

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.