Skip to contents

The li_media_upload function uploads a media file (e.g., an image) to LinkedIn for use in posts or other content. It first initializes the upload process with LinkedIn’s API, then uploads the media file to the provided upload URL.

Usage

li_media_upload(author, media)

Arguments

author

A character string representing the LinkedIn profile or organization ID in the format urn:li:person:XXXX or urn:li:organization:XXXX. This identifies the owner of the media being uploaded.

media

A character string representing the file path to the media (e.g., an image file) to be uploaded.

Value

A character string representing the LinkedIn image URL that can be used to reference the uploaded media in subsequent API calls.

Details

The function performs the following steps:

  1. Initializes the media upload by sending a request to the LinkedIn API.

  2. Extracts the uploadUrl from the response, which specifies where to upload the media file.

  3. Uploads the media file to the uploadUrl.

  4. Returns the image URL generated by LinkedIn for referencing the uploaded file.

The li_req() function, assumed to create an authenticated LinkedIn API request, must be available in the calling environment.

Examples

if (FALSE) { # \dontrun{
# Assign LinkedIn author and media to upload
author <- "urn:li:person:123456789"
media <- "path/to/image.png"

# Upload the media file
image_url <- li_media_upload(author, media)

# Use the returned image URL in a post
image_url
} # }