Skip to content

Commit 2035373

Browse files
Merge pull request HootsuiteLabs#2 from HootsuiteLabs/dev2
checkin diff between repo and pypi version
2 parents 982c86e + 98c9a94 commit 2035373

File tree

3 files changed

+132
-7
lines changed

3 files changed

+132
-7
lines changed

PKG-INFO

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
Metadata-Version: 1.1
2+
Name: python-linkedin-v2
3+
Version: 0.9.1
4+
Summary: Python Interface to the LinkedIn API V2
5+
Home-page: https://github.com/HootsuiteLabs/python-linkedin-v2
6+
Author: Rei Colina
7+
Author-email: [email protected]
8+
License: MIT
9+
Description: Python LinkedIn
10+
=================
11+
12+
Python interface to the LinkedIn API
13+
14+
This library provides a pure Python interface to the LinkedIn **Profile**, **Group**, **Company**, **Jobs**, **Search**, **Share**, **Network** and **Invitation** REST APIs.
15+
16+
`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.
17+
18+
Installation
19+
--------------------
20+
21+
You can install **python-linkedin** library via pip:
22+
23+
.. code-block:: bash
24+
25+
$ pip install python-linkedin
26+
27+
Authentication
28+
-----------------------
29+
30+
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>`_.
31+
32+
For debugging purposes you can use the credentials below. It belongs to my test application. Nothing's harmful.
33+
34+
.. code-block:: python
35+
36+
KEY = 'wFNJekVpDCJtRPFX812pQsJee-gt0zO4X5XmG6wcfSOSlLocxodAXNMbl0_hw3Vl'
37+
SECRET = 'daJDa6_8UcnGMw1yuq9TjoO_PMKukXMo8vEMo7Qv5J-G3SPgrAV0FqFCd0TNjQyG'
38+
39+
40+
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:
41+
42+
.. code-block:: python
43+
44+
from linkedin import linkedin
45+
46+
API_KEY = "wFNJekVpDCJtRPFX812pQsJee-gt0zO4X5XmG6wcfSOSlLocxodAXNMbl0_hw3Vl"
47+
API_SECRET = "daJDa6_8UcnGMw1yuq9TjoO_PMKukXMo8vEMo7Qv5J-G3SPgrAV0FqFCd0TNjQyG"
48+
RETURN_URL = "http://localhost:8000"
49+
# Optionally one can send custom "state" value that will be returned from OAuth server
50+
# It can be used to track your user state or something else (it's up to you)
51+
# Be aware that this value is sent to OAuth server AS IS - make sure to encode or hash it
52+
#authorization.state = 'your_encoded_message'
53+
authentication = linkedin.LinkedInAuthentication(API_KEY, API_SECRET, RETURN_URL, linkedin.PERMISSIONS.enums.values())
54+
print authentication.authorization_url
55+
application = linkedin.LinkedInApplication(authentication)
56+
57+
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**:
58+
59+
.. code-block:: python
60+
61+
"http://localhost:8000/?code=AQTXrv3Pe1iWS0EQvLg0NJA8ju_XuiadXACqHennhWih7iRyDSzAm5jaf3R7I8&state=ea34a04b91c72863c82878d2b8f1836c"
62+
63+
64+
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.
65+
66+
.. code-block:: python
67+
68+
authentication.authorization_code = "AQTXrv3Pe1iWS0EQvLg0NJA8ju_XuiadXACqHennhWih7iRyDSzAm5jaf3R7I8"
69+
authentication.get_access_token()
70+
71+
72+
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,
73+
one can directly assign the access token obtained before to the application instance.
74+
75+
76+
.. code-block:: python
77+
78+
application = linkedin.LinkedInApplication(token='AQTFtPILQkJzXHrHtyQ0rjLe3W0I')
79+
80+
81+
Quick Usage From Python Interpreter
82+
---------------------------------------------------------
83+
84+
For testing the library using an interpreter, use the quick helper.
85+
86+
.. code-block:: python
87+
88+
from linkedin import server
89+
application = server.quick_api(KEY, SECRET)
90+
91+
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.
92+
93+
.. code-block:: python
94+
95+
application.get_profile()
96+
97+
98+
More
99+
-----------------
100+
For more information, visit the `homepage <http://ozgur.github.com/python-linkedin/>`_ of the project.
101+
102+
Keywords: linkedin python
103+
Platform: UNKNOWN
104+
Classifier: Development Status :: 5 - Production/Stable
105+
Classifier: Environment :: Console
106+
Classifier: Intended Audience :: Developers
107+
Classifier: License :: OSI Approved :: MIT License
108+
Classifier: Operating System :: OS Independent
109+
Classifier: Programming Language :: Python :: 2.7
110+
Classifier: Programming Language :: Python :: 3
111+
Classifier: Programming Language :: Python :: 3.4
112+
Classifier: Natural Language :: English

linkedin_v2/linkedin.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,6 @@ def make_request(self, method, url, data=None, params=None, headers=None,
171171

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

174-
def get_profile(self, member_id=None, member_url=None, selectors=None,
175-
params=None, headers=None):
176-
url = '%s/me' % ENDPOINTS.BASE
177-
response = self.make_request('GET', url, params=params, headers=headers)
178-
raise_for_error(response)
179-
return response.json()
180-
181174
def get_connections(self, totals_only=None, params=None, headers=None):
182175
count = '50'
183176
if totals_only:
@@ -186,3 +179,18 @@ def get_connections(self, totals_only=None, params=None, headers=None):
186179
response = self.make_request('GET', url, params=params, headers=headers)
187180
raise_for_error(response)
188181
return response.json()
182+
183+
def get_profile(self, member_id=None, member_url=None, selectors=None,
184+
params=None, headers=None):
185+
connections = 0
186+
if selectors is not None and 'num-connections' in selectors:
187+
connections_response = self.get_connections(totals_only=True)
188+
connections_body = connections_response.get('paging', None)
189+
connections = connections_body.get('total', 0)
190+
191+
url = '%s/me' % ENDPOINTS.BASE
192+
response = self.make_request('GET', url, params=params, headers=headers)
193+
raise_for_error(response)
194+
json_response = response.json()
195+
json_response.update({'numConnections': connections})
196+
return json_response

setup.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[egg_info]
2+
tag_build =
3+
tag_date = 0
4+
tag_svn_revision = 0
5+

0 commit comments

Comments
 (0)