-
-
Save sharonhoward/476ee5f7eab0402a09f0e08356be0a8c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ------------------------------------------------------------------------------------------ | |
| # Basically all translated from the Python example at https://atproto.com/blog/create-post | |
| # ------------------------------------------------------------------------------------------ | |
| library(httr2) | |
| # Create a logged-in API session object | |
| session <- request("https://bsky.social/xrpc/com.atproto.server.createSession") |> | |
| req_method("POST") |> | |
| req_body_json(list( | |
| identifier = Sys.getenv("BSKY_USER"), | |
| password = Sys.getenv("BSKY_PASS") | |
| )) |> | |
| req_perform() |> | |
| resp_body_json() | |
| # This is the token you can use for other API calls: | |
| # session$accessJwt | |
| # Create a post as a list | |
| post_body <- list( | |
| "$type" = "app.bsky.feed.post", | |
| text = "Test post from {httr2}", | |
| createdAt = format(as.POSIXct(Sys.time(), tz = "UTC"), "%Y-%m-%dT%H:%M:%OS6Z"), | |
| langs = list("en-US") | |
| ) | |
| # Post the post | |
| resp <- request("https://bsky.social/xrpc/com.atproto.repo.createRecord") |> | |
| req_method("POST") |> | |
| req_headers(Authorization = paste0("Bearer ", session$accessJwt)) |> | |
| req_body_json(list( | |
| repo = session$did, | |
| collection = "app.bsky.feed.post", | |
| record = post_body | |
| )) | |
| # Actually make the request and post the thing | |
| resp |> req_perform() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment