Links

Create contacts from linkedin post likes

Tags: #hubspot #crm #sales #contact #naas_drivers #linkedin #post #contact #snippet
Author: Florent Ravenel
Description: This notebook create new contacts based on LinkedIn post likes.

Input

Import librairies

from naas_drivers import linkedin, hubspot
import naas
import requests

Setup HubSpot

👉 Starting November 30, 2022, HubSpot API keys no longer enable access to HubSpot APIs, so in Naas version 2.8.3 and above, you need create a private app and use the access token.
# Enter Your Access Token
HS_ACCESS_TOKEN = naas.secret.get("HS_ACCESS_TOKEN") or "YOUR_HS_ACCESS_TOKEN"

Setup LinkedIn

If you are using the Chrome Extension:
  • Copy/Paste your token in your extension
  • Login/Logout your LinkedIn account
  • Your secrets "LINKEDIN_LI_AT" and "LINKEDIN_JSESSIONID" will be added directly on your naas everytime you login and logout.
or
If you are not using the Google Chrome Extension, learn how to get your cookies on LinkedIn and set up the values below:
  • 🍪 li_at
  • 🍪 JSESSIONID
# Cookies
LI_AT = naas.secret.get("LINKEDIN_LI_AT") or "YOUR_COOKIE_LI_AT"
JSESSIONID = naas.secret.get("LINKEDIN_JSESSIONID") or "YOUR_COOKIE_JSESSIONID"
# Post URL
POST_URL = "----"

Model

Get post likes

df_posts = linkedin.connect(LI_AT, JSESSIONID).post.get_likes(POST_URL)
# Display the number of likes
print("Number of likes: ", df_posts.PROFILE_URN.count())
# Show dataframe with list of profiles from likes
df_posts

Create contacts from LinkedIn post likes

def create_contacts_from_post(
df,
c_profile_urn="PROFILE_URN",
c_firstname="FIRSTNAME",
c_lastname="LASTNAME",
c_occupation="OCCUPATION",
):
for _, row in df.iterrows():
profile_urn = row[c_profile_urn]
firstname = row[c_firstname]
lastname = row[c_lastname]
occupation = row[c_occupation]
linkedinbio = f"https://www.linkedin.com/in/{profile_urn}"
email = None
phone = None
# contact
try:
contact = linkedin.connect(LI_AT, JSESSIONID).profile.get_contact(
linkedinbio
)
email = contact.loc[0, "EMAIL"]
phone = contact.loc[0, "PHONENUMBER"]
except:
print("No contact info")
# With send method
data = {
"properties": {
"linkedinbio": linkedinbio,
"firstname": firstname,
"lastname": lastname,
"jobtitle": occupation,
"email": email,
"phone": phone,
}
}
print(data)
hubspot.connect(HS_ACCESS_TOKEN).contacts.send(data)

Output

Display result

create_contacts_from_post(df_posts)