├── README.md └── tomquirk_linkedin_api.ipynb /README.md: -------------------------------------------------------------------------------- 1 | # linkedin_api 2 | Linkedin API for Python 3 | 4 | This notebook (tomquirk_linkedin_api.ipynb) aims to access data from LinkedIn by using an open source library by Tom Quirk. 5 | 6 | See Tom Quirk's open source library here: https://github.com/tomquirk/linkedin-api 7 | 8 | See more endpoints in reference documentation: https://linkedin-api.readthedocs.io/en/latest/api.html 9 | 10 | Requirement: Python >= 3.6 11 | -------------------------------------------------------------------------------- /tomquirk_linkedin_api.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Linkedin API for Python" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "This notebook aims to access data from LinkedIn by using an open source library by Tom Quirk.\n", 15 | "\n", 16 | "See Tom Quirk's open source library here: https://github.com/tomquirk/linkedin-api\n", 17 | "\n", 18 | "See more endpoints in reference documentation: https://linkedin-api.readthedocs.io/en/latest/api.html\n", 19 | "\n", 20 | "Requirement: Python version >= 3.6" 21 | ] 22 | }, 23 | { 24 | "cell_type": "code", 25 | "execution_count": 1, 26 | "metadata": {}, 27 | "outputs": [ 28 | { 29 | "name": "stdout", 30 | "output_type": "stream", 31 | "text": [ 32 | "Collecting git+https://github.com/tomquirk/linkedin-api.git\n", 33 | " Cloning https://github.com/tomquirk/linkedin-api.git to c:\\users\\admin\\appdata\\local\\temp\\pip-req-build-j9lgj_8d\n", 34 | "Requirement already satisfied: requests in c:\\users\\admin\\anaconda3\\lib\\site-packages (from linkedin-api==2.0.0a5) (2.24.0)\n", 35 | "Requirement already satisfied: beautifulsoup4 in c:\\users\\admin\\anaconda3\\lib\\site-packages (from linkedin-api==2.0.0a5) (4.9.1)\n", 36 | "Requirement already satisfied: lxml in c:\\users\\admin\\anaconda3\\lib\\site-packages (from linkedin-api==2.0.0a5) (4.5.2)\n", 37 | "Requirement already satisfied: idna<3,>=2.5 in c:\\users\\admin\\anaconda3\\lib\\site-packages (from requests->linkedin-api==2.0.0a5) (2.10)\n", 38 | "Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in c:\\users\\admin\\anaconda3\\lib\\site-packages (from requests->linkedin-api==2.0.0a5) (1.25.9)\n", 39 | "Requirement already satisfied: chardet<4,>=3.0.2 in c:\\users\\admin\\anaconda3\\lib\\site-packages (from requests->linkedin-api==2.0.0a5) (3.0.4)\n", 40 | "Requirement already satisfied: certifi>=2017.4.17 in c:\\users\\admin\\anaconda3\\lib\\site-packages (from requests->linkedin-api==2.0.0a5) (2020.6.20)\n", 41 | "Requirement already satisfied: soupsieve>1.2 in c:\\users\\admin\\anaconda3\\lib\\site-packages (from beautifulsoup4->linkedin-api==2.0.0a5) (2.0.1)\n", 42 | "Building wheels for collected packages: linkedin-api\n", 43 | " Building wheel for linkedin-api (setup.py): started\n", 44 | " Building wheel for linkedin-api (setup.py): finished with status 'done'\n", 45 | " Created wheel for linkedin-api: filename=linkedin_api-2.0.0a5-py3-none-any.whl size=22240 sha256=6a5c0fb6132d699dd80a3b89102e357053a25370ea1c782ae5eb769834d50536\n", 46 | " Stored in directory: C:\\Users\\Admin\\AppData\\Local\\Temp\\pip-ephem-wheel-cache-0vwgip8f\\wheels\\4a\\1e\\c9\\dde2839868d836bedb613857d1bb4620eb93046a3861cb08de\n", 47 | "Successfully built linkedin-api\n", 48 | "Installing collected packages: linkedin-api\n", 49 | "Successfully installed linkedin-api-2.0.0a5\n" 50 | ] 51 | }, 52 | { 53 | "name": "stderr", 54 | "output_type": "stream", 55 | "text": [ 56 | " Running command git clone -q https://github.com/tomquirk/linkedin-api.git 'C:\\Users\\Admin\\AppData\\Local\\Temp\\pip-req-build-j9lgj_8d'\n" 57 | ] 58 | } 59 | ], 60 | "source": [ 61 | "#install package\n", 62 | "!pip install git+https://github.com/tomquirk/linkedin-api.git" 63 | ] 64 | }, 65 | { 66 | "cell_type": "code", 67 | "execution_count": null, 68 | "metadata": {}, 69 | "outputs": [], 70 | "source": [] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "execution_count": null, 75 | "metadata": {}, 76 | "outputs": [], 77 | "source": [] 78 | }, 79 | { 80 | "cell_type": "markdown", 81 | "metadata": {}, 82 | "source": [ 83 | "## Get API access using Linkedin login credentials\n", 84 | "\n", 85 | "If you are using Two-step verification for sign In, you have to turn it off temporarily.\n", 86 | "\n", 87 | "Go to: Settings & Privacy -> Sign in & security -> Two-step verification -> Turn off" 88 | ] 89 | }, 90 | { 91 | "cell_type": "code", 92 | "execution_count": 1, 93 | "metadata": {}, 94 | "outputs": [], 95 | "source": [ 96 | "from linkedin_api import Linkedin\n", 97 | "\n", 98 | "# Authenticate using the normal Linkedin account login credentials\n", 99 | "# Be sure to disable 2-Factor Authentication (temporarily), and REMEMBER to enable it again after!\n", 100 | "api = Linkedin('my_linkedin_account@email.com', 'my_password')" 101 | ] 102 | }, 103 | { 104 | "cell_type": "code", 105 | "execution_count": 2, 106 | "metadata": {}, 107 | "outputs": [ 108 | { 109 | "data": { 110 | "text/plain": [ 111 | "{'email_address': 'jnyh@yahoo.com',\n", 112 | " 'websites': [{'url': 'https://github.com/JNYH', 'label': 'PORTFOLIO'},\n", 113 | " {'url': 'https://towardsdatascience.com/@jnyh', 'label': 'BLOG'}],\n", 114 | " 'twitter': [],\n", 115 | " 'birthdate': None,\n", 116 | " 'ims': None,\n", 117 | " 'phone_numbers': []}" 118 | ] 119 | }, 120 | "execution_count": 2, 121 | "metadata": {}, 122 | "output_type": "execute_result" 123 | } 124 | ], 125 | "source": [ 126 | "# GET a profile contact info, for example https://www.linkedin.com/in/jnyh/\n", 127 | "contact_info = api.get_profile_contact_info('jnyh')\n", 128 | "contact_info" 129 | ] 130 | }, 131 | { 132 | "cell_type": "code", 133 | "execution_count": 4, 134 | "metadata": {}, 135 | "outputs": [ 136 | { 137 | "data": { 138 | "text/plain": [ 139 | "'ACoAAC___BUBzW8S1c74w6QZEnpXPJxjSy13XvQ'" 140 | ] 141 | }, 142 | "execution_count": 4, 143 | "metadata": {}, 144 | "output_type": "execute_result" 145 | } 146 | ], 147 | "source": [ 148 | "# GET a profile URN\n", 149 | "profile = api.get_profile('jnyh')\n", 150 | "profile['profile_id']" 151 | ] 152 | }, 153 | { 154 | "cell_type": "code", 155 | "execution_count": null, 156 | "metadata": {}, 157 | "outputs": [], 158 | "source": [] 159 | }, 160 | { 161 | "cell_type": "code", 162 | "execution_count": null, 163 | "metadata": {}, 164 | "outputs": [], 165 | "source": [] 166 | }, 167 | { 168 | "cell_type": "markdown", 169 | "metadata": {}, 170 | "source": [ 171 | "## To expand the DataFrens network" 172 | ] 173 | }, 174 | { 175 | "cell_type": "code", 176 | "execution_count": 1, 177 | "metadata": {}, 178 | "outputs": [], 179 | "source": [ 180 | "from linkedin_api import Linkedin\n", 181 | "\n", 182 | "# Authenticate using the normal Linkedin account login credentials\n", 183 | "api = Linkedin('my_linkedin_account@email.com', 'my_password')" 184 | ] 185 | }, 186 | { 187 | "cell_type": "code", 188 | "execution_count": null, 189 | "metadata": {}, 190 | "outputs": [], 191 | "source": [ 192 | "frens_list = [\n", 193 | " 'dr-alvin',\n", 194 | " 'jnyh',\n", 195 | " 'teoyongsong',\n", 196 | " 'steven-chua-4125b6110',\n", 197 | " 'dwight-fonseka-279646102',\n", 198 | " 'mohamed-feroz-kuthubdeen-6b79aa15',\n", 199 | " 'patrickohwl',\n", 200 | " 'DUPLICATE_THE_ABOVE_LINE_AND_EDIT_PUBLIC_ID'\n", 201 | "]" 202 | ] 203 | }, 204 | { 205 | "cell_type": "code", 206 | "execution_count": 5, 207 | "metadata": {}, 208 | "outputs": [ 209 | { 210 | "name": "stdout", 211 | "output_type": "stream", 212 | "text": [ 213 | "Connection added: dr-alvin\n", 214 | "Connection added: jnyh\n" 215 | ] 216 | } 217 | ], 218 | "source": [ 219 | "for fren in frens_list:\n", 220 | " try:\n", 221 | " profile = api.get_profile(fren)\n", 222 | " profile_urn = profile['profile_id']\n", 223 | " firstName = profile['firstName'].strip()\n", 224 | " lastName = profile['lastName'].strip()\n", 225 | " if api.add_connection(profile_public_id=fren, message='Connection from DataFrens added', profile_urn=profile_urn) == False:\n", 226 | " print('Connection added:', fren, '|', firstName, lastName) #for this API, True means error, False means successfully added\n", 227 | " else:\n", 228 | " print('FAILED:', fren) #it seems ok to add myself or add my existing connection to my own network\n", 229 | " except:\n", 230 | " print('EXCEPTION:', fren)" 231 | ] 232 | }, 233 | { 234 | "cell_type": "code", 235 | "execution_count": null, 236 | "metadata": {}, 237 | "outputs": [], 238 | "source": [] 239 | }, 240 | { 241 | "cell_type": "code", 242 | "execution_count": null, 243 | "metadata": {}, 244 | "outputs": [], 245 | "source": [] 246 | }, 247 | { 248 | "cell_type": "markdown", 249 | "metadata": {}, 250 | "source": [ 251 | "## When done, please turn ON Two-step verification, for better security!\n", 252 | "Go to: Settings & Privacy -> Sign in & security -> Two-step verification -> Turn ON\n", 253 | "\n", 254 | "This will help to safeguard your account, in the (very unlikely) event that the HTTPS data got hacked in transit!" 255 | ] 256 | }, 257 | { 258 | "cell_type": "code", 259 | "execution_count": null, 260 | "metadata": {}, 261 | "outputs": [], 262 | "source": [] 263 | }, 264 | { 265 | "cell_type": "code", 266 | "execution_count": null, 267 | "metadata": {}, 268 | "outputs": [], 269 | "source": [] 270 | }, 271 | { 272 | "cell_type": "code", 273 | "execution_count": null, 274 | "metadata": {}, 275 | "outputs": [], 276 | "source": [] 277 | }, 278 | { 279 | "cell_type": "code", 280 | "execution_count": null, 281 | "metadata": {}, 282 | "outputs": [], 283 | "source": [] 284 | } 285 | ], 286 | "metadata": { 287 | "kernelspec": { 288 | "display_name": "Python 3", 289 | "language": "python", 290 | "name": "python3" 291 | }, 292 | "language_info": { 293 | "codemirror_mode": { 294 | "name": "ipython", 295 | "version": 3 296 | }, 297 | "file_extension": ".py", 298 | "mimetype": "text/x-python", 299 | "name": "python", 300 | "nbconvert_exporter": "python", 301 | "pygments_lexer": "ipython3", 302 | "version": "3.8.3" 303 | } 304 | }, 305 | "nbformat": 4, 306 | "nbformat_minor": 4 307 | } 308 | --------------------------------------------------------------------------------