From f763584d4d6afe618de032523586f1813ce138a9 Mon Sep 17 00:00:00 2001 From: benman1 Date: Fri, 16 Mar 2018 15:14:47 +0000 Subject: [PATCH] converted to python3 --- README.md | 11 ++++-- examples/authentication.py | 4 +- linkedin/server.py | 80 +++++++++++++++++++------------------- 3 files changed, 49 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index 9967ef0..0854374 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # Python LinkedIn +Forked and converted to python3. + + Python interface to the LinkedIn API [![LinkedIn](http://developer.linkedin.com/sites/default/files/LinkedIn_Logo60px.png)](http://developer.linkedin.com) @@ -82,7 +85,7 @@ authentication = linkedin.LinkedInAuthentication(API_KEY, API_SECRET, RETURN_URL # 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' -print authentication.authorization_url # open this url on your browser +print(authentication.authorization_url) # open this url on your browser 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**: @@ -385,7 +388,7 @@ There are many network update types. You can look at them by importing **NETWORK ```python from linkedin.linkedin import NETWORK_UPDATES -print NETWORK_UPDATES.enums +print(NETWORK_UPDATES.enums) {'APPLICATION': 'APPS', 'CHANGED_PROFILE': 'PRFU', 'COMPANY': 'CMPY', @@ -425,13 +428,13 @@ The Invitation API allows your users to invite people they find in your applicat ```python from linkedin.models import LinkedInRecipient, LinkedInInvitation recipient = LinkedInRecipient(None, 'john.doe@python.org', 'John', 'Doe') -print recipient.json +print(recipient.json) {'person': {'_path': '/people/email=john.doe@python.org', 'first-name': 'John', 'last-name': 'Doe'}} invitation = LinkedInInvitation('Hello John', "What's up? Can I add you as a friend?", (recipient,), 'friend') -print invitation.json +print(invitation.json) {'body': "What's up? Can I add you as a friend?", 'item-content': {'invitation-request': {'connect-type': 'friend'}}, 'recipients': {'values': [{'person': {'_path': '/people/email=john.doe@python.org', diff --git a/examples/authentication.py b/examples/authentication.py index cb1a22b..8de19bc 100644 --- a/examples/authentication.py +++ b/examples/authentication.py @@ -7,6 +7,6 @@ API_SECRET = 'daJDa6_8UcnGMw1yuq9TjoO_PMKukXMo8vEMo7Qv5J-G3SPgrAV0FqFCd0TNjQyG' RETURN_URL = 'http://localhost:8000' authentication = LinkedInAuthentication(API_KEY, API_SECRET, RETURN_URL, - PERMISSIONS.enums.values()) - print authentication.authorization_url + list(PERMISSIONS.enums.values())) + print(authentication.authorization_url) application = LinkedInApplication(authentication) diff --git a/linkedin/server.py b/linkedin/server.py index 4032a2a..e59456c 100644 --- a/linkedin/server.py +++ b/linkedin/server.py @@ -1,40 +1,40 @@ -# -*- coding: utf-8 -*- -import BaseHTTPServer -import urlparse - -from .linkedin import LinkedInApplication, LinkedInAuthentication, PERMISSIONS - - -def quick_api(api_key, secret_key, port=8000): - """ - This method helps you get access to linkedin api quickly when using it - from the interpreter. - Notice that this method creates http server and wait for a request, so it - shouldn't be used in real production code - it's just an helper for debugging - - The usage is basically: - api = quick_api(KEY, SECRET) - After you do that, it will print a URL to the screen which you must go in - and allow the access, after you do that, the method will return with the api - object. - """ - auth = LinkedInAuthentication(api_key, secret_key, 'http://localhost:8000/', - PERMISSIONS.enums.values()) - app = LinkedInApplication(authentication=auth) - print auth.authorization_url - _wait_for_user_to_enter_browser(app, port) - return app - - -def _wait_for_user_to_enter_browser(app, port): - class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler): - def do_GET(self): - p = self.path.split('?') - if len(p) > 1: - params = urlparse.parse_qs(p[1], True, True) - app.authentication.authorization_code = params['code'][0] - app.authentication.get_access_token() - - server_address = ('', port) - httpd = BaseHTTPServer.HTTPServer(server_address, MyHandler) - httpd.handle_request() +# -*- coding: utf-8 -*- +import http.server +import urllib.parse + +from .linkedin import LinkedInApplication, LinkedInAuthentication, PERMISSIONS + + +def quick_api(api_key, secret_key, port=8000): + """ + This method helps you get access to linkedin api quickly when using it + from the interpreter. + Notice that this method creates http server and wait for a request, so it + shouldn't be used in real production code - it's just an helper for debugging + + The usage is basically: + api = quick_api(KEY, SECRET) + After you do that, it will print a URL to the screen which you must go in + and allow the access, after you do that, the method will return with the api + object. + """ + auth = LinkedInAuthentication(api_key, secret_key, 'http://localhost:8000/', + list(PERMISSIONS.enums.values())) + app = LinkedInApplication(authentication=auth) + print(auth.authorization_url) + _wait_for_user_to_enter_browser(app, port) + return app + + +def _wait_for_user_to_enter_browser(app, port): + class MyHandler(http.server.BaseHTTPRequestHandler): + def do_GET(self): + p = self.path.split('?') + if len(p) > 1: + params = urllib.parse.parse_qs(p[1], True, True) + app.authentication.authorization_code = params['code'][0] + app.authentication.get_access_token() + + server_address = ('', port) + httpd = http.server.HTTPServer(server_address, MyHandler) + httpd.handle_request()