- OCaml 99%
- Raku <1%
linkedin #
LinkedIn Voyager API client.
linkedin reads LinkedIn profiles, feed posts and Pulse articles, for
example to archive a member's own writing or republish it on a personal
site. It binds the internal Voyager API that LinkedIn's web client calls,
with typed values for each kind of item, and authenticates with the browser
session cookies li_at and JSESSIONID rather than OAuth, and its
command-line tool reads those cookies out of Chrome's encrypted cookie store
on macOS.
Voyager is undocumented and LinkedIn changes it without notice, so the response parsers walk the JSON by path rather than through fixed codecs, and a change on LinkedIn's side can break them.
The library uses requests for HTTP, nox-json for JSON, nox-cookie for
cookies, lambdasoup for article HTML, and Eio for concurrency.
Installation #
Install with opam:
$ opam install linkedin
If opam cannot find the package, it may not yet be released in the public
opam-repository. Add the overlay repository, then install it:
$ opam repo add samoht https://tangled.org/gazagnaire.org/opam-overlay.git
$ opam update
$ opam install linkedin
Usage #
Library #
let show_me ~li_at ~jsessionid =
Eio_main.run @@ fun env ->
Eio.Switch.run @@ fun sw ->
let api = Linkedin.Api.v ~sw env ~li_at ~jsessionid in
match Linkedin.Api.me api with
| Ok profile -> Fmt.pr "%a@." Linkedin.Profile.pp profile
| Error e -> Fmt.epr "%a@." Linkedin.Api.pp_error e
Command-line #
# One-time: authenticate by reading your Chrome session
linkedin login
linkedin logout # remove saved cookies
# Show your own profile
linkedin me
# Show another user's profile
linkedin profile johndoe
linkedin profile https://www.linkedin.com/in/johndoe
# Fetch any LinkedIn item (Pulse article or feed post)
linkedin get https://www.linkedin.com/pulse/my-article-johndoe-abcde/
linkedin get https://www.linkedin.com/feed/update/urn:li:activity:7123456789
# Choose the output format; the default is Markdown with YAML front matter
linkedin get <url> --format md # (default) via Item.to_markdown
linkedin get <url> --format html # raw article body HTML
linkedin get <url> --format json # structured record via Item.json
linkedin get <url> --json # alias for --format json
# Walk a person's recent feed (articles + posts, reverse-chronological)
linkedin feed johndoe
linkedin feed -n 500 johndoe
linkedin feed johndoe --json
API #
Apiis the HTTP client authenticated with theli_atandJSESSIONIDcookies, with theme,profile,postsandpostendpoints.Profileis a member profile: public identifier, name, headline, summary, location and entity URN, read from both theprofileViewand the/meresponses.Postis a feed post: URN, text, author name, timestamps and engagement counts.Chrome_cookiesextracts and decrypts the LinkedIn session cookies from Chrome's SQLite cookie store on macOS, with the key from the Keychain, PBKDF2 and AES-CBC.Urlparses profile, post and Pulse article URLs:/in/{id},/feed/update/urn:...,/posts/{slug}and/pulse/{slug}.Pulseis a Pulse article with its title, author, subtitle, publication date and body rendered as Markdown;fetchretrieves a public article by URL or slug. Most callers wantIteminstead.Htmlis the small typed decoder overlambdasoupthatPulseuses.Itemis either kind of item, a Pulse article or a feed post.getfetches one by URL, andfeedwalks a member's share feed and returns article and post summaries, newest first, with JSON codecs for a website or an ingestion pipeline.
License #
ISC