I have an issue using the linkedin-api library.
I want to check if somebody accepts my invitation, all this using the API.
I want to find a way to check on the invitations I made with “add_connection”.
In the Response header of add_connection there is a parameter named “Location” which I think is the relative URL of the place where is stored data about newly created invitation.
So i tried to retrieve it with linkedin._fetch(location_relative_url) , but I get a 400 error
For example the location_relative_url is like ‘/voyagerGrowthNormInvitations/7253503640567476224’,
Any clue about this ?
import os
import requests
from dotenv import load_dotenv, find_dotenv
from linkedin_api.linkedin import Linkedin
from linkedin_api.utils import helpers
dotenv_path = find_dotenv()
load_dotenv(dotenv_path)
# Vérifier la récupération des variables
username = os.getenv("LINKEDIN_USERNAME")
password = os.getenv("LINKEDIN_PASSWORD")
linkedin_url_test = "https://www.linkedin.com/in/david-ralambofiringa-mba-99052937/"
### Création du client et du script
cookies_dict = {
'li_at': os.getenv("li_at"),
'JSESSIONID': os.getenv("JSESSIONID"),
}
cookies = dict_to_cookiejar(cookies_dict)
linkedin = Linkedin(username=username, password=password, cookies=cookies)
public_id = extract_public_id(linkedin_url_test)
profile = linkedin.get_profile(public_id=public_id)
# Obtain URN_ID of profil
profile_urn = profile.get("profile_urn")
profile_urn_id = helpers.get_id_from_urn(profile_urn);
connexion_request = linkedin.add_connection(profile_public_id = public_id, profile_urn = profile_urn)
if connexion_request.status_code == 201:
# Accéder à l'url de la ressource créée
location_relative_url = connexion_request.headers.get("Location")
ressource = linkedin._fetch(location_relative_url)
print("ressource = ",ressource.content,ressource.text, ressource.json())
def extract_public_id(linkedin_url):
if not linkedin_url:
return None
if "https://www.linkedin.com/in/" in linkedin_url:
public_id = linkedin_url.split("/in/")[-1]
public_id = public_id.rstrip('/')
return public_id
return None
def dict_to_cookiejar(cookie_dict):
jar = requests.cookies.RequestsCookieJar()
for key, value in cookie_dict.items():
jar.set(key, value)
return jar