Skip to content

Instantly share code, notes, and snippets.

@sharonhoward
Forked from andrewheiss/httr2-bsky-atproto.R
Created September 23, 2023 07:22
Show Gist options
  • Save sharonhoward/476ee5f7eab0402a09f0e08356be0a8c to your computer and use it in GitHub Desktop.
Save sharonhoward/476ee5f7eab0402a09f0e08356be0a8c to your computer and use it in GitHub Desktop.

Revisions

  1. @andrewheiss andrewheiss revised this gist Sep 22, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion httr2-bsky-atproto.R
    Original file line number Diff line number Diff line change
    @@ -35,5 +35,5 @@ resp <- request("https://bsky.social/xrpc/com.atproto.repo.createRecord") |>
    record = post_body
    ))

    # Actuall make the request and post the thing
    # Actually make the request and post the thing
    resp |> req_perform()
  2. @andrewheiss andrewheiss revised this gist Sep 22, 2023. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions httr2-bsky-atproto.R
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,7 @@
    # ------------------------------------------------------------------------------------------
    # Basically all translated from the Python example at https://atproto.com/blog/create-post
    # ------------------------------------------------------------------------------------------

    library(httr2)

    # Create a logged-in API session object
  3. @andrewheiss andrewheiss revised this gist Sep 22, 2023. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions httr2-bsky-atproto.R
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    # Basically all translated from the Python example at https://atproto.com/blog/create-post
    library(httr2)

    # Create a logged-in API session object
  4. @andrewheiss andrewheiss created this gist Sep 22, 2023.
    35 changes: 35 additions & 0 deletions httr2-bsky-atproto.R
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    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
    ))

    # Actuall make the request and post the thing
    resp |> req_perform()