linkedin-api icon indicating copy to clipboard operation
linkedin-api copied to clipboard

Connect with the cookie / CHALLENGE error

Open ghost opened this issue 5 years ago • 11 comments

Hi all,

Hope you are all well !

I was wondering if we could bypass the CHALLENGE error like described in this repository: https://github.com/jqueguiner/lk_scraper#retrieving-cookie

That would be awesome.

Cheers, X

ghost avatar Aug 09 '20 08:08 ghost

@x0rzkov this is interesting. Has this worked for you? I'd be willing to give it a shot 🙌

tomquirk avatar Aug 19 '20 22:08 tomquirk

Yes, it is working. It avoids the captcha.

ghost avatar Aug 20 '20 07:08 ghost

Hi,

Hope you are all well !

When do you think you gonna implement the "LI_AT" cookie option ?

Cheers, X

ghost avatar Aug 30 '20 15:08 ghost

Hi,

Hope you are all well !

When do you think you gonna implement the "LI_AT" cookie option ?

Cheers, X

@tomquirk It will take away alot of pain of getting Challenge exception.

malhotraguy avatar Sep 02 '20 16:09 malhotraguy

Hi,

Hope you are all well !

When do you think you gonna implement the "LI_AT" cookie option ?

Cheers, X

Here's a documented example from a previous merge request to use to cookies to authenticate : https://github.com/tomquirk/linkedin-api/pull/102/commits/980799f24e7e6181e927ae8a7da60e88b297a461.

I think this documentation was overwritten by another merge/commit at some point but the code is still in the master

P.S: When I did this merge request, I added the JSESSIONID cookie which I think is used for the csrf token. I'm not sure if this is a mandatory one ?? I'd be interested to know this since the JSESSIONID last for ~3months whereas the LI_AT is valid for ~1year I believe

ghost avatar Sep 08 '20 08:09 ghost

@malhotraguy @x0rzkov @crouinicrouina, I'm looking into this now.

So when we authenticate, we store the whole cookie file, which should already include li_at.

Is this issue for adding a parameter to the Linkedin class that accepts an li_at? In which case, I think @crouinicrouina gave a great explanation on how to achieve this with custom cookies.

Let me know if I have missed something.

tomquirk avatar Sep 09 '20 22:09 tomquirk

You should be able to connect with cookies using either one of these methods

import pickle

# This .jr file is created once you do your first call using the LinkedIn API
with open("./my_custom_cookie.jr", "rb") as f: 
  cookies = pickle.load(f) # You can use the values from these cookies to use the second method

linkedin = Linkedin("", "", cookies=cookies)

profile = linkedin.get_profile('tom-quirk')
from requests.cookies import cookiejar_from_dict

cookies = cookiejar_from_dict(
    {
        "liap": "true",
        "li_at": os.environ["LINKEDIN_COOKIE_LI_AT"],
        "JSESSIONID": os.environ["LINKEDIN_COOKIE_JSESSIONID"],
    }
)
linkedin = Linkedin("", "", cookies=cookies)

profile = linkedin.get_profile('tom-quirk')

I'm interested to know whether it works the same with/without the LINKEDIN_COOKIE_JSESSIONID

ghost avatar Sep 12 '20 22:09 ghost

@tomquirk Why don't you check the cookies from COOKIE_PATH = os.path.join(LINKEDIN_API_USER_DIR, "cookies/") ? In my case, saved at:

C:\Program Files\Python38\lib\site-packages\linkedin_api\cookie_repository.py

import os
from pathlib import Path

HOME_DIR = str(Path.home())
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
LINKEDIN_API_USER_DIR = os.path.join(HOME_DIR, ".linkedin_api/")
COOKIE_PATH = os.path.join(LINKEDIN_API_USER_DIR, "cookies/")

It would avoid this right?

import pickle

# This .jr file is created once you do your first call using the LinkedIn API
with open("./my_custom_cookie.jr", "rb") as f: 
  cookies = pickle.load(f) # You can use the values from these cookies to use the second method

linkedin = Linkedin("", "", cookies=cookies)

profile = linkedin.get_profile('tom-quirk')

marcelogrsp avatar Mar 27 '21 11:03 marcelogrsp

Hi all,

Please follow up with using this script https://github.com/everping/Linkedin-Authentication-Challenge to pass the challenge, and once it passed the Linkedin auth will work properly.

muhammad-mamdouh avatar Jun 03 '21 11:06 muhammad-mamdouh

@muhammad-mamdouh I ran that script and entered my pin, and the script finished. But then I tried to use this repo's LI API and I'm still getting a challenge exception

himat avatar Dec 29 '22 21:12 himat

How did you solved this @himat ?

SinaArdehali avatar Jun 11 '23 18:06 SinaArdehali