A Python Library to interface with LinkedIn API, OAuth and JSON responses

Overview

#Overview Here's another library based on the LinkedIn API, OAuth and JSON responses.

Hope this documentation explains everything you need to get started. Any questions feel free to email me or inbox me.

#Install through pip...

pip install linkedin

If linkedin is already installed, pass -I to your install:

pip install -I linkedin

#Import LinkedIn library

from linkedin import *

#Authorization URL

Get an authorization url for your user

l = LinkedinAPI(api_key='*your app key*',
              api_secret='*your app secret*',
              callback_url='http://www.example.com/callback/',
              permissions=["r_network"])

auth_props = l.get_authentication_tokens()
auth_url = auth_props['auth_url']

#Store this token in a session or something for later use in the next step.
oauth_token_secret = auth_props['oauth_token_secret']

print 'Connect with LinkedIn via: %s' % auth_url

If you leave callback_url blank, you can get the oauth_verifier from the web browser. It is a five-digit integer.

The permissions parameter is optional. It can be a list or string. The list of permissions is in the LinkedIn API documentation.

Once you click "Allow" be sure that there is a URL set up to handle getting finalized tokens and possibly adding them to your database to use their information at a later date. \n\n'

#Handling the callback

# In Django, you'd do something like
# oauth_token = request.GET.get('oauth_token')
# oauth_verifier = request.GET.get('oauth_verifier')

oauth_token = *Grab oauth token from URL*
oauth_verifier = *Grab oauth verifier from URL*

#Initiate the LinkedIn class in your callback.
l = LinkedinAPI(api_key='*your app key*',
              api_secret='*your app secret*',
              oauth_token=oauth_token,
              oauth_token_secret=session['linkedin_session_keys']['oauth_token_secret'])

authorized_tokens = l.get_access_token(oauth_verifier)

final_oauth_token = authorized_tokens['oauth_token']
final_oauth_token_secret = authorized_tokens['oauth_token_secret']

# Save those tokens to the database for a later use?

#Getting some user information, search results, network updates.

# Get the final tokens from the database or wherever you have them stored

l = LinkedinAPI(api_key = '*your app key*',
              api_secret = '*your app secret*',
              oauth_token=final_tokens['oauth_token'],
              oauth_token_secret=final_tokens['oauth_token_secret'])

# Get your profile information (first name, last name)
profile = l.get('people/~', fields='first-name,last-name')
print profile

# Get search results
search = l.get('people-search', params={'keywords':'Hacker'})
print search

# Get your network updates
feed = l.get('people/~/network/updates')
print feed

POST a network update

share_content = { 
       "comment": "Posting from the API using JSON", 
       "content": { 
               "title": "A title for your share", 
               "submitted-url": "http://www.linkedin.com", 
               "submitted-image-url": "http://lnkd.in/Vjc5ec" 
       }, 
       "visibility": { 
               "code": "anyone" 
       } 
}

share_update = l.post('people/~/shares', params=share_content)
print share_update
Comments
  • How do you get the auth_verifier?

    How do you get the auth_verifier?

    I did not understand what you meant by:

    oauth_token = request.GET.get('oauth_verifier')

    oauth_verifier = request.GET.get('oauth_verifier')

    I know that is I input the auth_url on the browser while I´m logged on I can get the outh verifier number, but how can I do this programatically? I´m sorry if this sounds dumb, I´m relatively new in Python

    opened by Julioacarrettoni 7
  • Added changes that fixed issues with my implementation

    Added changes that fixed issues with my implementation

    Hello Michael

    1. README.md states that for installation, you have to run pip install linkedin -- however if someone wishes to add scope to the request, in version 0.1.2, permissions is not part of LinkedinAPI::init() property list. To fix this, I added a minor text change in the README.md file. The user should now call, pip install linkedin==0.1.3. I noted that when I called pip install linkedin after someone else had bumped the version 0.1.3, pip was still installing version 0.1.2.
    2. When trying to retrieve a requestToken and then accessToken, we were doing this by 'GET' method. However, documentation in http://developer.linkedin.com/documents/authentication states that these calls need to be of type 'POST'. -- I think there is a previous Pull Request with this change by evandekieft
    3. While revising how to implement authentication with Linkedin, I noticed that the documentation on http://developer.linkedin.com/documents/authentication stated that the authorize url is: https//www.linkedin.com/uas/oauth/authenticate?oauth_token=XXXXXXXXX. I also notice a very strange behavior when using the aus/oauth/authorize link, it kept asking me to "Allow access" even though I had given access rights to the application. After switching to the url specified in documentation, I was requested to "Allow access" once, and thereafter, it would just redirect me to the correct authenticated callback url stated in the application callback url field.

    Thanks, -e

    opened by egonzalez777 3
  • get_access_token

    get_access_token

    The most important thing is function: get_access_token, since LinkedIn complains about the missing parameter oauth_token when sending the POST request

    opened by c0x6a 2
  • Problems with imports

    Problems with imports

    During importing the LinkedinAPI class from your package, it throws an error

    from urlparse import parse_qsl
    ModuleNotFoundError: No module named 'urlparse'
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/home/andrew/.local/lib/python3.8/site-packages/linkedin.py", line 13, in <module>
        from cgi import parse_qsl
    ImportError: cannot import name 'parse_qsl' from 'cgi' (/usr/lib/python3.8/cgi.py)
    

    I was wondering if you could resolve these problems with your imports.

    opened by pandrey2003 1
  • Return status code with exception

    Return status code with exception

    Would be nice to return the status code from linkedin when an exception is raised. https://github.com/rossdeane/linkedin/commit/82543502de1c9757c6e9a6195418480ebb9f7f7d

    opened by rossdeane 1
  • Better handling of oauth_callback parameter to requestToken endpoint

    Better handling of oauth_callback parameter to requestToken endpoint

    Hi Michael,

    I ran into an issue in using this library to call the requestToken endpoint with an oauth_callback URL that itself contains parameters. Since the existing code is just doing a GET against the requestToken endpoint and appending oauth_callback as a URL parameter, when the callback URL itself has parameters, they get mixed up. So one fix would just be to percent-encode this; but since the LinkedIn Authentication docs suggest POST is the preferable method, I updated the code to send the oauth_callback in the POST body instead, and this works for me now.

    By the way, ignore the other pull request I sent before, this one replaces it.

    opened by evandekieft-zz 1
  • Better handling of oauth_callback parameter to requestToken endpoint

    Better handling of oauth_callback parameter to requestToken endpoint

    Hi Michael,

    I ran into an issue in using this library when passing an oauth_callback URL that itself contains parameters. The requestToken endpoint was being hit with a GET and the callback URL was simply appended; but when the callback URL itself contains parameters, this doesn't work properly. One could percent-encode the callback URL but since the LinkedIn Authentication docs suggest POST is the preferred method, I just do that instead. This fixed the issue for me.

    opened by CircleUp 0
  • session definition

    session definition

    I'm trying to get the final_oauth_token and secret and in initiating the linkedin class the oauth_token_secret is defined as so: oauth_token_secret=session['linkedin_session_keys']['oauth_token_secret'] I must be missing something or not understanding it, but session doesn't seem to be defined anywhere. Or maybe it doesn't work now because it was last modified years ago. Please clarify.

    opened by thisisadds 1
  • How to get this oauth_token_secret

    How to get this oauth_token_secret

    In Linkediin package:

    How to get this - oauth_token_secret = session['linkedin_session_keys']['oauth_token_secret']) ?

    from where do we get linkedin _session_keys ?

    Without this geting an error when obtaining final tokens

    Can any one help me in this regard?

    opened by kumarvn 0
  • Improved handling of errors

    Improved handling of errors

    This improves the error handling a bit, so errors can easier be introspected when they happen. This is to have better error handling for know cases, f.ex. expired tokens.

    opened by holm 0
Owner
Mike Helmick
Mike Helmick
A Python Library to interface with Tumblr v2 REST API & OAuth

Tumblpy Tumblpy is a Python library to help interface with Tumblr v2 REST API & OAuth Features Retrieve user information and blog information Common T

Mike Helmick 125 Jun 20, 2022
Python interface to the LinkedIn API

Python LinkedIn Python interface to the LinkedIn API This library provides a pure Python interface to the LinkedIn Profile, Group, Company, Jobs, Sear

ozgur 844 Dec 27, 2022
👨‍💼Linkedin API for Python

linkedin_api ??‍?? Linkedin API for Python No "official" API access required - just use a valid Linkedin account! Programmatically send messages, get

Tom Quirk 918 Dec 29, 2022
Finds Jobs on LinkedIn using web-scraping

Find Jobs on LinkedIn ?? This program finds jobs by scraping on LinkedIn ??‍?? Relies on User Input. Accepts: Country, City, State ?? Data about jobs

Matt 44 Dec 27, 2022
Easy-apply-bot - A LinkedIn Easy Apply bot to help with my job search.

easy-apply-bot A LinkedIn Easy Apply bot to help with my job search. Getting Started First, clone the repository somewhere onto your computer, or down

Matthew Alunni 5 Dec 9, 2022
Proxy server that records responses for UI testing (and other things)

Welcome to playback-proxy ?? A proxy tool that records communication (requests, websockets) between client and server. This recording can later be use

Yurii 41 Apr 1, 2022
This repository provides a set functions to extract paragraphs from AWS Textract responses.

extract-paragraphs-with-aws-textract Since AWS Textract (the AWS OCR service) does not have a native function to extract paragraphs, this repository p

Juan Anzola 3 Jan 26, 2022
A Python script to create customised Spotify playlists using the JSON, Spotipy Library and Spotify Web API, based on seed tracks in your history.

A Python script to create customised Spotify playlists using the JSON, Spotipy Library and Spotify Web API, based on seed tracks in your history.

Youngseo Park 1 Feb 1, 2022
Python client for Invidious' JSON API

Python project template A template for new Python projects. Features Automatically builds PDoc documentation & uploads package to PyPI on new GitHub r

Kevo 2 Jun 5, 2022
NewpaperNews-API - Json data of the news with python

NewsAPI API Documentation BASE_URL = "https://saurav.tech/NewsAPI/" top_headline

Aryaman Prakash 2 Sep 23, 2022
It connects to Telegram's API. It generates JSON files containing channel's data, including channel's information and posts.

It connects to Telegram's API. It generates JSON files containing channel's data, including channel's information and posts. You can search for a specific channel, or a set of channels provided in a text file (one channel per line.)

Esteban Ponce de Leon 75 Jan 2, 2023
A simple waybar module to display the status of the ICE you are currently in using the ICE Portals JSON API.

waybar-iceportal A simple waybar module to display the status of the ICE you are currently in using the ICE Portals JSON API. Installation Ensure pyth

Moritz 7 Aug 26, 2022
Read API docs offline, CLI, supports DevDocs.io compatible JSON files

Read API docs offline, CLI, supports DevDocs.io compatible JSON files

Tero Karvinen 3 Oct 18, 2022
Automated JSON API based communication with Fronius Symo

PyFronius - a very basic Fronius python bridge A package that connects to a Fronius device in the local network and provides data that is provided via

Niels Mündler 10 Dec 30, 2022
alpaca-trade-api-python is a python library for the Alpaca Commission Free Trading API.

alpaca-trade-api-python is a python library for the Alpaca Commission Free Trading API. It allows rapid trading algo development easily, with support for both REST and streaming data interfaces

Alpaca 1.5k Jan 9, 2023
Full-featured Python interface for the Slack API

This repository is archived and will not receive any updates It's time to say goodbye. I'm archiving Slacker. It's been getting harder to find time to

Oktay Sancak 1.6k Dec 13, 2022
TeslaPy - A Python implementation based on unofficial documentation of the client side interface to the Tesla Motors Owner API

TeslaPy - A Python implementation based on unofficial documentation of the client side interface to the Tesla Motors Owner API, which provides functiona

Tim Dorssers 233 Dec 30, 2022
⛑ REDCap API interface in Python

REDCap API in Python Description Supports structured data extraction for REDCap projects. The API module d3b_redcap_api.redcap.REDCapStudy can be logi

D3b 1 Nov 21, 2022
A Python package designed to help users of Cisco's FMC interface with its API.

FMCAPI was originally developed by Dax Mickelson ([email protected]). Dax has moved on to other projects but has kindly transferred the ownership of

Mark Sullivan 66 Dec 13, 2022