summaryrefslogtreecommitdiff
path: root/internal/platforms/linkedin/linkedin.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2024-10-08 11:00:32 +0300
committerPaul Buetow <paul@buetow.org>2024-10-08 11:00:32 +0300
commit8e30ad597bf200c2f3be22262364a6f4e1af1a36 (patch)
tree3eea2d66f09ad5f73ee9a65cc1077162820b335b /internal/platforms/linkedin/linkedin.go
parent2bc4585db96da4000fbf727beadfc25af64bcd4a (diff)
more on the linkedin oauth refactoring. need to test the changes, though.
Diffstat (limited to 'internal/platforms/linkedin/linkedin.go')
-rw-r--r--internal/platforms/linkedin/linkedin.go21
1 files changed, 12 insertions, 9 deletions
diff --git a/internal/platforms/linkedin/linkedin.go b/internal/platforms/linkedin/linkedin.go
index 6205234..768def5 100644
--- a/internal/platforms/linkedin/linkedin.go
+++ b/internal/platforms/linkedin/linkedin.go
@@ -6,31 +6,34 @@ import (
"encoding/json"
"fmt"
"io"
- "log"
"net/http"
- "codeberg.org/snonux/gos/gosdir/db/platforms/linkedin/oauth2"
"codeberg.org/snonux/gos/internal/config"
"codeberg.org/snonux/gos/internal/entry"
+ "codeberg.org/snonux/gos/internal/platforms/linkedin/oauth2"
)
// TODO: Also implemebt a Text Platform output, which then laster can be
// processed by Gemtexter as a page
func Post(ctx context.Context, args config.Args, ent entry.Entry) error {
- secrets, err := oauth2.AccessToken(args)
+ content, err := ent.Content()
+ if err != nil {
+ return nil
+ }
+
+ personID, accessToken, err := oauth2.LinkedInOauth2Creds(args)
if err != err {
return err
}
- // TODO: Don't log this anymore
- log.Println("DEBUG", "Got access token", secrets)
- return nil
+
+ return post(personID, accessToken, content)
}
-func postMessage(secrets config.Secrets, message string) error {
+func post(personID, accessToken, message string) error {
const url = "https://api.linkedin.com/v2/posts"
post := map[string]interface{}{
- "author": fmt.Sprintf("urn:li:person:%s", secrets.LinkedInPesonID),
+ "author": fmt.Sprintf("urn:li:person:%s", personID),
"commentary": message,
"visibility": "PUBLIC",
"distribution": map[string]interface{}{
@@ -52,7 +55,7 @@ func postMessage(secrets config.Secrets, message string) error {
return fmt.Errorf("Error creating request: %w", err)
}
- req.Header.Add("Authorization", "Bearer "+secrets.LinkedInAccessToken)
+ req.Header.Add("Authorization", "Bearer "+accessToken)
req.Header.Set("Content-Type", "application/json")
req.Header.Add("X-RestLi-Protocol-Version", "2.0.0")