Links
Comment on page

Send like to post

Tags: #linkedin #socialmedia #like #post #python #api
Author: Florent Ravenel
Last update: 2023-08-02 (Created: 2023-08-02)
Description: This notebook will show how to send a like to a post published on LinkedIn.
Disclaimer: This code is in no way affiliated with, authorized, maintained, sponsored or endorsed by Linkedin or any of its affiliates or subsidiaries. It uses an independent and unofficial API. Use at your own risk.
This project violates Linkedin's User Agreement Section 8.2, and because of this, Linkedin may (and will) temporarily or permanently ban your account. We are not responsible for your account being banned.

Input

Import libraries

from naas_drivers import linkedin
import requests
import naas

Setup variables

Mandatory
  • li_at: Cookie used to authenticate Members and API clients
  • JSESSIONID: Cookie used for Cross Site Request Forgery (CSRF) protection and URL signature validation
Optional
  • post_url: This variable represents the post URL
  • reaction_type: This variable represents the type of reaction to sent to the post. It could be "LIKE", "PRAISE", "APPRECIATION", "EMPATHY", "INTEREST", "ENTERTAINMENT"
# Mandatory
li_at = naas.secret.get("LINKEDIN_LI_AT") or "YOUR_LINKEDIN_LI_AT" #example: AQFAzQN_PLPR4wAAAXc-FCKmgiMit5FLdY1af3-2
JSESSIONID = naas.secret.get("LINKEDIN_JSESSIONID") or "YOUR_LINKEDIN_JSESSIONID" #example: ajax:8379907400220387585
post_url = ""
# Optional
reaction_type = "LIKE" # "PRAISE", "APPRECIATION", "EMPATHY", "INTEREST", "ENTERTAINMENT"

Model

Connect to LinkedIn

LK = linkedin.connect(li_at, JSESSIONID)
cookies = LK.cookies
headers = LK.headers

Send like to post

def send_like(
cookies,
headers,
post_url,
reaction_like
):
# Check post URL
response = None
if not post_url.startswith("https://www.linkedin.com/"):
print("🛑 Post URL not valid! Please update it in the input section.")
return response
# Parse url to get activity id
if ":activity:" in post_url:
activity_tag = ":activity:"
tag_end = "?"
elif "-activity-" in post_url:
activity_tag = "-activity-"
tag_end = "-"
activity_id = post_url.split(activity_tag)[-1].split(tag_end)[0]
# Send like
url = f"https://www.linkedin.com/voyager/api/voyagerSocialDashReactions?threadUrn=urn%3Ali%3Aactivity%3A{activity_id}"
payload = {"reactionType": reaction_like}
response = requests.post(url, headers=headers, cookies=cookies, json=payload)
return response
res = send_like(
cookies,
headers,
post_url,
reaction_type
)

Output

Display result

if res:
if res.status_code == 201:
print("👍 Like sent to:", post_url)
else:
print(res.json())