Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func main() {

// Create a draft post.
p, err := m.CreatePost(medium.CreatePostOptions{
UserID: u.ID,
UserID: u.ID, // Or PublicationId: "your publication id"
Title: "Title",
Content: "<h2>Title</h2><p>Content</p>",
ContentFormat: medium.ContentFormatHTML,
Expand Down
9 changes: 8 additions & 1 deletion medium.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ type fileOpener interface {
// CreatePostOptions defines the options for creating a post on Medium.
type CreatePostOptions struct {
UserID string `json:"-"`
PublicationId string `json:"-"`
Title string `json:"title"`
Content string `json:"content"`
ContentFormat ContentFormat `json:"contentFormat"`
Expand Down Expand Up @@ -288,9 +289,15 @@ func (m *Medium) GetPublicationContributors(publicationID string) (*Contributors
// CreatePost creates a post on the profile identified by the current AccessToken.
// This requires m.AccessToken to have the PublishPost scope.
func (m *Medium) CreatePost(o CreatePostOptions) (*Post, error) {
var path string
if o.PublicationId != "" {
path = fmt.Sprintf("/v1/publications/%s/posts", o.PublicationId)
} else {
path = fmt.Sprintf("/v1/users/%s/posts", o.UserID)
}
r := clientRequest{
method: "POST",
path: fmt.Sprintf("/v1/users/%s/posts", o.UserID),
path: path,
data: o,
}
p := &Post{}
Expand Down