Post on Linkedin

To use this code, you need to follow these steps:

  1. Open a Google Sheet where you want to post updates on LinkedIn.
  2. Go to the “Tools” menu and select “Script editor.”
  3. Copy and paste the code I provided into the script editor.
  4. Replace the ACCESS_TOKEN placeholder in the code with your actual LinkedIn API access token.
  5. Save the script and close the script editor.
  6. Go back to your Google Sheet and enter the message and link for the update in separate columns.
  7. Run the script by selecting the function name (postOnLinkedIn) from the “Run” menu.

When you run the script, it will loop through the rows of data in the active sheet, retrieve the message and link for each row, and use the LinkedIn API to post the update on your behalf.

The code to paste in Apps Script section:


function postOnLinkedIn() { // Get the active sheet var sheet = SpreadsheetApp.getActiveSheet(); // Get the data range var range = sheet.getDataRange(); var values = range.getValues(); // Loop through the rows of data for (var i = 1; i < values.length; i++) { var row = values[i]; // Get the message and link from the row var message = row[0]; var link = row[1]; // Post on LinkedIn var options = { "method": "post", "payload": { "comment": message, "content": { "contentEntities": [ { "thumbnails": [ { "resolvedUrl": "https://example.com/image.jpg" } ], "title": "Title", "description": "Description", "contentUrl": link, "entityLocation": link } ], "title": "Title", "description": "Description" }, "visibility": { "com.linkedin.ugc.MemberNetworkVisibility": "PUBLIC" } }, "headers": { "Authorization": "Bearer ACCESS_TOKEN", "Content-Type": "application/json" } }; var response = UrlFetchApp.fetch("https://api.linkedin.com/v2/ugcPosts", options); Logger.log(response.getContentText()); }
}


Reach us if the process is unclear or if the script is outdated
Apps Scripts template

Post on Linkedin

Last updated
4/4/2023
Built by
Avatar Placeholder
internal

This script allows you to post updates on LinkedIn from a Google Sheet. It uses the LinkedIn API to create a new post with a message and a link to a web page. The message and link are retrieved from the active sheet in the Google Sheet.