-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunner-li.R
More file actions
88 lines (78 loc) · 2.41 KB
/
runner-li.R
File metadata and controls
88 lines (78 loc) · 2.41 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# 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_req <- li_base |>
httr2::req_url("https://api.linkedin.com/v2/me")
author_id <- li_perform(author_req) |> httr2::resp_body_json() |> _$id
author <- glue::glue("urn:li:person:{author_id}")
# The new LinkedIn API uses markdown, so escape _ so it isn't confused.
status_msg <- stringr::str_replace_all(
status_msg,
stringr::fixed("_"),
"\\_"
)
if (
length(metadata) &&
length(metadata$credit$linkedin) &&
!is.na(metadata$credit$linkedin) &&
metadata$credit$linkedin != ""
) {
li_name <- stringr::str_split_1(metadata$credit$linkedin, "@") |>
stringr::str_squish() |>
stringr::str_subset("\\S")
li_credit <- paste0(
"https://www.linkedin.com/in/",
li_name
)
credit <- paste(
"Curator:",
stringr::str_flatten_comma(glue::glue("{li_name} {li_credit}"))
)
if (length(credit)) {
status_msg <- paste(credit, status_msg, sep = "\n\n")
}
}
# 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", # Owned by Jon
# id = "urn:li:image:D562CAQEXGJZvRPNQEQ", # Owned by Lydia
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")