Send connections from network to gsheet

Tags: #linkedin #network #connections #naas_drivers #csv #automation #content #googlesheets
Author: Florent Ravenel
Last update: 2023-05-29 (Created: 2022-03-17)
Description: This notebook allows users to export their LinkedIn connections to a Google Sheet for easy organization and tracking.
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.


Import libraries

from naas_drivers import linkedin, gsheet
import naas
import pandas as pd

Setup LinkedIn

# Lindekin cookies
LI_AT = "AQEDARCNSioDe6wmAAABfqF-HR4AAAF-xYqhHlYAtSu7EZZEpFer0UZF-GLuz2DNSz4asOOyCRxPGFjenv37irMObYYgxxxxxxx"

Setup your Google Sheet

👉 Get your spreadsheet URL 👉 Share your gsheet with our service account to connect : [email protected] 👉 Create your sheet before sending data into it
# Spreadsheet URL
# Sheet name

Setup Naas

naas.scheduler.add(cron="0 8 * * *")
# -> To delete your scheduler, please uncomment the line below and execute this cell
# naas.scheduler.delete()


Get connections from Google Sheet

df_gsheet = gsheet.connect(SPREADSHEET_URL).get(sheet_name=SHEET_NAME)

Get new connections

def get_new_connections(df_gsheet, key="PROFILE_URN"):
profiles = []
if len(df_gsheet) > 0:
profiles = df_gsheet[key].unique()
df = linkedin.connect(LI_AT, JSESSIONID).network.get_connections(limit=-1)
return df
# Get new
df_new = pd.DataFrame()
update = True
while update:
start = 0
df = linkedin.connect(LI_AT, JSESSIONID).network.get_connections(
start=start, count=100, limit=100
new_profiles = df[key].unique()
for i, p in enumerate(new_profiles):
if p in profiles:
update = False
df = df[:i]
start += 100
df_new = pd.concat([df_new, df])
return df_new
df_new = get_new_connections(df_gsheet, key="PROFILE_URN")


Send to Google Sheet

gsheet.connect(SPREADSHEET_URL).send(df_new, sheet_name=SHEET_NAME, append=True)