Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
checkin diff between repo and pypi version
  • Loading branch information
william-beange-hs committed Mar 2, 2018
commit 98c9a948089db79c3f0c19b0c702bc7d5e2e44cf
112 changes: 112 additions & 0 deletions PKG-INFO
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
Metadata-Version: 1.1
Name: python-linkedin-v2
Version: 0.9.1
Summary: Python Interface to the LinkedIn API V2
Home-page: https://github.com/HootsuiteLabs/python-linkedin-v2
Author: Rei Colina
Author-email: [email protected]
License: MIT
Description: Python LinkedIn
=================

Python interface to the LinkedIn API

This library provides a pure Python interface to the LinkedIn **Profile**, **Group**, **Company**, **Jobs**, **Search**, **Share**, **Network** and **Invitation** REST APIs.

`LinkedIn <http://developer.linkedin.com>`_ provides a service that lets people bring their LinkedIn profiles and networks with them to your site or application via their OAuth based API. This library provides a lightweight interface over a complicated LinkedIn OAuth based API to make it for python programmers easy to use.

Installation
--------------------

You can install **python-linkedin** library via pip:

.. code-block:: bash

$ pip install python-linkedin

Authentication
-----------------------

LinkedIn REST API uses **Oauth 2.0** protocol for authentication. In order to use the LinkedIn API, you have an **application key** and **application secret**. You can get more detail from `here <http://developers.linkedin.com/documents/authentication>`_.

For debugging purposes you can use the credentials below. It belongs to my test application. Nothing's harmful.

.. code-block:: python

KEY = 'wFNJekVpDCJtRPFX812pQsJee-gt0zO4X5XmG6wcfSOSlLocxodAXNMbl0_hw3Vl'
SECRET = 'daJDa6_8UcnGMw1yuq9TjoO_PMKukXMo8vEMo7Qv5J-G3SPgrAV0FqFCd0TNjQyG'


LinkedIn redirects the user back to your website's URL after granting access (giving proper permissions) to your application. We call that url **RETURN URL**. Assuming your return url is **http://localhost:8000**, you can write something like this:

.. code-block:: python

from linkedin import linkedin

API_KEY = "wFNJekVpDCJtRPFX812pQsJee-gt0zO4X5XmG6wcfSOSlLocxodAXNMbl0_hw3Vl"
API_SECRET = "daJDa6_8UcnGMw1yuq9TjoO_PMKukXMo8vEMo7Qv5J-G3SPgrAV0FqFCd0TNjQyG"
RETURN_URL = "http://localhost:8000"
# Optionally one can send custom "state" value that will be returned from OAuth server
# It can be used to track your user state or something else (it's up to you)
# Be aware that this value is sent to OAuth server AS IS - make sure to encode or hash it
#authorization.state = 'your_encoded_message'
authentication = linkedin.LinkedInAuthentication(API_KEY, API_SECRET, RETURN_URL, linkedin.PERMISSIONS.enums.values())
print authentication.authorization_url
application = linkedin.LinkedInApplication(authentication)

When you grant access to the application, you will be redirected to the return url with the following query strings appended to your **RETURN_URL**:

.. code-block:: python

"http://localhost:8000/?code=AQTXrv3Pe1iWS0EQvLg0NJA8ju_XuiadXACqHennhWih7iRyDSzAm5jaf3R7I8&state=ea34a04b91c72863c82878d2b8f1836c"


This means that the value of the **authorization_code** is **AQTXrv3Pe1iWS0EQvLg0NJA8ju_XuiadXACqHennhWih7iRyDSzAm5jaf3R7I8**. After setting it by hand, we can call the **.get_access_token()** to get the actual token.

.. code-block:: python

authentication.authorization_code = "AQTXrv3Pe1iWS0EQvLg0NJA8ju_XuiadXACqHennhWih7iRyDSzAm5jaf3R7I8"
authentication.get_access_token()


After you get the access token, you are now permitted to make API calls on behalf of the user who granted access to you app. In addition to that, in order to prevent from going through the OAuth flow for every consecutive request,
one can directly assign the access token obtained before to the application instance.


.. code-block:: python

application = linkedin.LinkedInApplication(token='AQTFtPILQkJzXHrHtyQ0rjLe3W0I')


Quick Usage From Python Interpreter
---------------------------------------------------------

For testing the library using an interpreter, use the quick helper.

.. code-block:: python

from linkedin import server
application = server.quick_api(KEY, SECRET)

This will print the authorization url to the screen. Go into this URL using a browser, after you login, the method will return with an API object you can now use.

.. code-block:: python

application.get_profile()


More
-----------------
For more information, visit the `homepage <http://ozgur.github.com/python-linkedin/>`_ of the project.

Keywords: linkedin python
Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.4
Classifier: Natural Language :: English
22 changes: 15 additions & 7 deletions linkedin_v2/linkedin.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,6 @@ def make_request(self, method, url, data=None, params=None, headers=None,

return requests.request(method.upper(), url, **kw)

def get_profile(self, member_id=None, member_url=None, selectors=None,
params=None, headers=None):
url = '%s/me' % ENDPOINTS.BASE
response = self.make_request('GET', url, params=params, headers=headers)
raise_for_error(response)
return response.json()

def get_connections(self, totals_only=None, params=None, headers=None):
count = '50'
if totals_only:
Expand All @@ -186,3 +179,18 @@ def get_connections(self, totals_only=None, params=None, headers=None):
response = self.make_request('GET', url, params=params, headers=headers)
raise_for_error(response)
return response.json()

def get_profile(self, member_id=None, member_url=None, selectors=None,
params=None, headers=None):
connections = 0
if selectors is not None and 'num-connections' in selectors:
connections_response = self.get_connections(totals_only=True)
connections_body = connections_response.get('paging', None)
connections = connections_body.get('total', 0)

url = '%s/me' % ENDPOINTS.BASE
response = self.make_request('GET', url, params=params, headers=headers)
raise_for_error(response)
json_response = response.json()
json_response.update({'numConnections': connections})
return json_response
5 changes: 5 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[egg_info]
tag_build =
tag_date = 0
tag_svn_revision = 0