Phase 6 part 4: post as the LinkedIn company page
A second LinkedIn app (Community Management API) with its own sign-in on Settings → Social accounts: the pages the member may post for are listed and one chosen, new LinkedIn drafts default to the page or to you, and each draft can switch before it's published. Schema 25. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -62,13 +62,24 @@ func (s *Server) publishers() content.Publishers {
|
||||
}
|
||||
pubs[content.ChannelX] = xPublisher{c}
|
||||
}
|
||||
var li linkedInPublisher
|
||||
if tok, urn := s.Secrets.Get(secrets.LinkedInAccessToken), s.Secrets.Get(secrets.LinkedInAuthorURN); tok != "" && urn != "" {
|
||||
if e := s.linkedInExpiry(); e != nil && e.Expired() {
|
||||
pubs[content.ChannelLinkedIn] = expiredPublisher{*e}
|
||||
li.meErr = expiredPublisher{*e}.err()
|
||||
} else {
|
||||
pubs[content.ChannelLinkedIn] = linkedInPublisher{linkedin.New(tok, urn)}
|
||||
li.me = linkedin.New(tok, urn)
|
||||
}
|
||||
}
|
||||
if tok, org := s.Secrets.Get(secrets.LinkedInPageAccessToken), s.liPage(); tok != "" && org != nil {
|
||||
if e := s.linkedInPageExpiry(); e != nil && e.Expired() {
|
||||
li.pageErr = expiredPublisher{*e}.err()
|
||||
} else {
|
||||
li.page = linkedin.New(tok, org.URN)
|
||||
}
|
||||
}
|
||||
if li.me != nil || li.page != nil || li.meErr != nil || li.pageErr != nil {
|
||||
pubs[content.ChannelLinkedIn] = li
|
||||
}
|
||||
if c := s.redditUser(); c != nil {
|
||||
pubs[content.ChannelReddit] = redditPublisher{s: s, c: c}
|
||||
}
|
||||
@@ -80,7 +91,11 @@ func (s *Server) publishers() content.Publishers {
|
||||
type expiredPublisher struct{ e Expiry }
|
||||
|
||||
func (p expiredPublisher) Publish(context.Context, content.Post) (string, error) {
|
||||
return "", fmt.Errorf("%s's sign-in expired on %s: reconnect %s under Settings → Social accounts, then publish again",
|
||||
return "", p.err()
|
||||
}
|
||||
|
||||
func (p expiredPublisher) err() error {
|
||||
return fmt.Errorf("%s's sign-in expired on %s: reconnect %s under Settings → Social accounts, then publish again",
|
||||
p.e.Network, p.e.At.Local().Format("2 Jan 2006"), p.e.Network)
|
||||
}
|
||||
|
||||
@@ -96,12 +111,23 @@ func (p xPublisher) Publish(ctx context.Context, post content.Post) (string, err
|
||||
return p.c.PostTweet(ctx, text)
|
||||
}
|
||||
|
||||
type linkedInPublisher struct{ c *linkedin.Client }
|
||||
|
||||
// Publish attaches the source link as an article preview.
|
||||
func (p linkedInPublisher) Publish(ctx context.Context, post content.Post) (string, error) {
|
||||
c := p.me
|
||||
switch {
|
||||
case post.AsPage && p.pageErr != nil:
|
||||
return "", p.pageErr
|
||||
case post.AsPage && p.page == nil:
|
||||
return "", errNoPage
|
||||
case post.AsPage:
|
||||
c = p.page
|
||||
case p.meErr != nil:
|
||||
return "", p.meErr
|
||||
case p.me == nil:
|
||||
return "", errNoMe
|
||||
}
|
||||
if post.SourceURL == "" {
|
||||
return p.c.PostUpdate(ctx, post.Text, nil)
|
||||
return c.PostUpdate(ctx, post.Text, nil)
|
||||
}
|
||||
// LinkedIn wants the card's title from us. A page that can't be read
|
||||
// still gets a card, titled with its address.
|
||||
@@ -109,7 +135,7 @@ func (p linkedInPublisher) Publish(ctx context.Context, post content.Post) (stri
|
||||
ictx, cancel := context.WithTimeout(ctx, 10*time.Second)
|
||||
defer cancel()
|
||||
link.Title, link.Description, _ = site.PageInfo(ictx, post.SourceURL, "Supermarket/1 (link preview)")
|
||||
return p.c.PostUpdate(ctx, post.Text, link)
|
||||
return c.PostUpdate(ctx, post.Text, link)
|
||||
}
|
||||
|
||||
type redditPublisher struct {
|
||||
|
||||
Reference in New Issue
Block a user