-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner-li.R
62 lines (53 loc) · 1.64 KB
/
runner-li.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Do the common tasks.
source("runner-shared.R", local = TRUE)
source("helpers-linkedin.R", local = TRUE)
# At least for now, we use the same image for every TT post on LinkedIn.
alt_text <- paste(
"Logo for the #TidyTuesday Project. The words TidyTuesday overlaying",
"a black paint splash"
)
author <- "urn:li:person:mBbHaQfQtg"
# The new LinkedIn API uses markdown, so escape _ so it isn't confused.
status_msg <- stringr::str_replace_all(
status_msg,
stringr::fixed("_"),
"\\_"
)
# We have more room, so include more info.
status_msg <- status_msg |>
paste(
"\nNew to #TidyTuesday?",
"Welcome to the weekly social data project. All are welcome!",
"⬡ The event is organized by the Data Science Learning Community https://dslc.io",
"⬡ For the latest datasets, follow DSLC on Mastodon or LinkedIn",
sep = "\n"
)
li_post <- li_base |>
httr2::req_url_path_append("posts") |>
httr2::req_body_json(
list(
author = author,
commentary = status_msg,
visibility = "PUBLIC",
distribution = list(
feedDistribution = "MAIN_FEED",
targetEntities = list(),
thirdPartyDistributionChannels = list()
),
content = list(
media = list(
id = "urn:li:image:D5622AQEHKFmWxhSlJQ",
altText = alt_text
)
),
lifecycleState = "PUBLISHED",
isReshareDisabledByAuthor = FALSE
)
)
posted <- li_perform(li_post)
if (httr2::resp_status(posted) != 201) {
stop("LinkedIn broke!")
}
post_id <- httr2::resp_header(posted, "x-linkedin-id")
attr(post_id, "week") <- lubridate::week(lubridate::now())
saveRDS(post_id, "li_post_id.rds")