def oauth_callback(request): authentication = LinkedInAuthentication(settings.SOCIAL_AUTH_LINKEDIN_OAUTH2_KEY, settings.SOCIAL_AUTH_LINKEDIN_OAUTH2_SECRET, settings.RETURN_URL, [PERMISSIONS.BASIC_PROFILE, PERMISSIONS.EMAIL_ADDRESS]) if request.method == 'GET': form = OAuthCallbackForm(request.GET) if form.is_valid(): """cleaned_code = form.cleaned_data['code'] cleaned_state = form.cleaned_data['state'] return HttpResponse("Code: " + cleaned_code + "\nState: " + cleaned_state)""" authentication.authorization_code = form.cleaned_data['code'] token = authentication.get_access_token() # store access token in session request.session['linkedin_access_token'] = token application = LinkedInApplication(token=token) # get profile from LinkedIn profile_data = application.get_profile(selectors=['id', 'first-name', 'last-name', 'location', 'industry', 'email-address', 'summary']) # Try to get summary data try: summary = profile_data['summary'] except KeyError: summary = '' # Get existing profile in database try: profile_db = Profile.objects.get(user_id=profile_data['id']) profile_db.user_id=profile_data['id'] profile_db.first_name=profile_data['firstName'] profile_db.last_name=profile_data['lastName'] profile_db.email=profile_data['emailAddress'] profile_db.summary=summary profile_db.industry=profile_data['industry'] profile_db.location_name=profile_data['location']['name'] except Profile.DoesNotExist: profile_db = Profile(user_id=profile_data['id'], first_name=profile_data['firstName'], last_name=profile_data['lastName'], email=profile_data['emailAddress'], summary=summary, industry=profile_data['industry'], location_name=profile_data['location']['name']) # store profile profile_db.save() request.session['linkedin_userid'] = profile_data['id'] # redirect to search page return HttpResponseRedirect("/search/")
def getLinkedinProf(self,user_key,user_secret): API_KEY = 'your key' API_SECRET = 'your secret' RETURN_URL = 'http://127.0.0.1:5000/' USER_KEY= user_key USER_SECRET=user_secret authentication = LinkedInDeveloperAuthentication(API_KEY, API_SECRET, USER_KEY,USER_SECRET,RETURN_URL, PERMISSIONS.enums.values()) #developer as user application = LinkedInApplication(authentication) selectors=['id', 'first-name', 'last-name', 'location', 'distance', 'num-connections', 'skills', 'educations','summary','positions','projects','connections'] return selectors,application.get_profile(selectors=selectors)
def convert(source, crossrefQuery='', token=''): global application if token == '': authentication = LinkedInAuthentication(API_KEY, API_SECRET, RETURN_URL, PERMISSIONS.enums.values()) authorization_url = authentication.authorization_url authorization_url = authorization_url.replace( '%20r_fullprofile', '').replace('%20rw_groups', '').replace( '%20w_messages', '').replace('%20r_contactinfo', '').replace( '%20r_network', '%20rw_company_admin').replace('%20rw_nus', '%20w_share') #print authorization_url cmd = 'open "' + authorization_url + '"' print cmd msg = subprocess.check_output(cmd, shell=True) else: authentication = LinkedInAuthentication(API_KEY, API_SECRET, RETURN_URL, PERMISSIONS.enums.values()) authentication.authorization_code = token access_token = authentication.get_access_token() print access_token[0] application = LinkedInApplication(authentication=authentication, token=access_token[0]) if application != None: #print application.get_profile() #response = application.make_request('GET', 'https://api.linkedin.com/v1/people/~') #response = application.make_request('GET', 'https://api.linkedin.com/v1/companies::(universal-name=dog)') #https://stackoverflow.com/questions/30409219/linkedin-api-unable-to-view-any-company-profile response = application.get_companies(universal_names='naughty dog') print str(response) return ''
def response1(request): code = request.GET['code'] API_KEY = "75b6nt9kewzh8f" API_SECRET = "xdhRsXeOAAi9tXB3" RETURN_URL = "http://127.0.0.1:8000/linkedin/response1" authentication = LinkedInAuthentication(API_KEY,API_SECRET,RETURN_URL,PERMISSIONS.enums.values()) authentication.authorization_code = code authentication.get_access_token() application = LinkedInApplication(authentication) profile = application.get_profile(selectors=['id', 'first-name', 'last-name','headline', 'location', 'distance', 'num-connections', 'skills', 'educations']) connections = application.get_connections() return render_to_response('linkedin/profile.html',{'profile':profile, 'connections':connections})
class LinkedInWrapper(object): """ Simple namespacing """ authentication = LinkedInAuthentication( API_KEY, API_SECRET, 'http://127.0.0.1:8000/get_access_token', ['r_basicprofile']) application = LinkedInApplication(authentication)
def __init__(self, id, secret, port): self.id = id self.secret = secret self.callback_url = 'http://localhost:{0}/code/'.format(port) print("CLIENT ID: %s" % self.id) print("CLIENT SECRET: %s" % self.secret) print("Callback URL: %s" % self.callback_url) self.authentication = LinkedInAuthentication(self.id, self.secret, self.callback_url, permissions=[ 'r_basicprofile', 'r_emailaddress', 'rw_company_admin', 'w_share' ]) # Note: edit permissions according to what you defined in the linkedin # developer console. self.application = LinkedInApplication(self.authentication) print("Please double check that the callback URL has been correctly " "added in the developer console (" "https://www.linkedin.com/developer/apps/), then open " "http://localhost:8080 in your browser\n\n")
def get_linkedin_authorized(): code = request.args.get("code") state = request.args.get("state") cache[state].authorization_code = code token = cache[state].get_access_token() application = LinkedInApplication(token=token) profile = application.get_profile(selectors=[ 'id', 'first-name', 'last-name', 'maiden-name', 'formatted-name', 'phonetic-first-name', 'phonetic-last-name', 'formatted-phonetic-name', 'headline', 'location', 'industry', 'current-share', 'num-connections', 'num-connections-capped', 'summary', 'specialties', 'positions', 'picture-url', 'picture-urls', 'site-standard-profile-request', 'api-standard-profile-request', 'public-profile-url', 'email-address' ]) return render_template("index.html", linkedin_profile=application.get_profile())
class LinkedInWrapper(object): """ Simple namespacing """ API_KEY = 'wFNJekVpDCJtRPFX812pQsJee-gt0zO4X5XmG6wcfSOSlLocxodAXNMbl0_hw3Vl' API_SECRET = 'daJDa6_8UcnGMw1yuq9TjoO_PMKukXMo8vEMo7Qv5J-G3SPgrAV0FqFCd0TNjQyG' RETURN_URL = 'http://localhost:{0}/code'.format(globals()['PORT']) authentication = LinkedInAuthentication(API_KEY, API_SECRET, RETURN_URL, PERMISSIONS.enums.values()) application = LinkedInApplication(authentication)
class LinkedInWrapper(object): """ Simple namespacing """ API_KEY = environ.get('LINKEDIN_API_KEY') API_SECRET = environ.get('LINKEDIN_API_SECRET') RETURN_URL = 'http://localhost:{0}/code'.format(globals()['PORT']) authentication = LinkedInAuthentication(API_KEY, API_SECRET, RETURN_URL, PERMISSIONS.enums.values()) application = LinkedInApplication(authentication)
class LinkedInWrapper(object): """ Simple namespacing """ CLIENT_ID = get_environ('LINKEDIN_CLIENT_ID') CLIENT_SECRET = get_environ('LINKEDIN_CLIENT_SECRET') RETURN_URL = f'http://localhost:{PORT}/code' authentication = LinkedInAuthentication( CLIENT_ID, CLIENT_SECRET, RETURN_URL, ["r_liteprofile", "r_emailaddress"]) application = LinkedInApplication(authentication)
class LinkedInWrapper(object): """ Simple namespacing """ # API_KEY = 'wFNJekVpDCJtRPFX812pQsJee-gt0zO4X5XmG6wcfSOSlLocxodAXNMbl0_hw3Vl' # API_SECRET = 'daJDa6_8UcnGMw1yuq9TjoO_PMKukXMo8vEMo7Qv5J-G3SPgrAV0FqFCd0TNjQyG' API_KEY = '779u3cu8a069wz' API_SECRET = 'bcDwGS7N3GxcuiYD' RETURN_URL = 'http://localhost:{0}/code'.format(globals()['PORT']) authentication = LinkedInAuthentication(API_KEY, API_SECRET, RETURN_URL, ["r_liteprofile", "w_member_social", "r_emailaddress"]) application = LinkedInApplication(authentication)
def get_user(self): if not self.accessToken(): return None app = LinkedInApplication(token=self.accessToken()) profile = app.get_profile(selectors=['id', 'first-name', 'last-name', 'email-address']) if profile: if not profile.has_key('username'): username = profile['id'] else: username = profile['username'] if not profile.has_key('emailAddress'): email = '%s.fakemail' %(profile['id']) else: email = profile['emailAddress'] return dict(first_name = profile['firstName'], last_name = profile['lastName'], username = username, email = '%s' %(email), registration_id = 'ln_' + profile['id'] )
def __init__(self, id, secret, port, auth_token=None, auth_code=None): self.id = id self.secret = secret self.callback_url = 'http://localhost:{0}/code/'.format(port) #self.callback_url = 'http://socialanalytics.msrcosmos.com' print("CLIENT ID: %s" % self.id) print("CLIENT SECRET: %s" % self.secret) print("Callback URL: %s" % self.callback_url) if auth_token == None: self.authentication = LinkedInAuthentication( self.id, self.secret, self.callback_url, permissions=[ 'r_basicprofile', 'r_emailaddress', 'rw_company_admin', 'w_share' ]) if auth_code == None: print( "Please open this address in your browser in order to obtain the authorization_code\n\n" ) print(self.authentication.authorization_url) print( "\n\nIn case of error, please double check that the callback URL has been correctly added in the developer console: https://www.linkedin.com/developer/apps/" ) sys.exit() else: self.authentication.authorization_code = auth_code result = self.authentication.get_access_token() print("\n\nAccess Token:", result.access_token) print("Expires in (seconds):", result.expires_in) sys.exit() else: print self.application = LinkedInApplication(token=auth_token)
def quick_api(api_key, secret_key): """ 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) return app
from linkedin.linkedin import (LinkedInAuthentication, LinkedInApplication, PERMISSIONS) if __name__ == '__main__': API_KEY = '75q0rlkmhlgpa2' API_SECRET = 'MT0Dr4xxlbpUDC5e' RETURN_URL = 'http://localhost:8000' authentication = LinkedInAuthentication(API_KEY, API_SECRET, RETURN_URL, PERMISSIONS.enums.values()) print authentication.authorization_url application = LinkedInApplication(authentication) application.get_companies(company_ids=[1035], universal_names=['apple'], selectors=['name'], params={'is-company-admin': 'true'})
from PyLinkedinAPI.PyLinkedinAPI import PyLinkedinAPI from linkedin.linkedin import LinkedInAuthentication, LinkedInApplication, PERMISSIONS port = 8000 API_KEY = "wFNJekVpDCJtRPFX812pQsJee-gt0zO4X5XmG6wcfSOSlLocxodAXNMbl0_hw3Vl" API_SECRET = "daJDa6_8UcnGMw1yuq9TjoO_PMKukXMo8vEMo7Qv5J-G3SPgrAV0FqFCd0TNjQyG" RETURN_URL = "http://localhost:8000" auth = LinkedInAuthentication(API_KEY, API_SECRET, 'http://localhost:8000/', PERMISSIONS.enums.values()) app = LinkedInApplication(authentication=auth) print auth.authorization_url_wait_for_user_to_enter_browser(app, port)
from linkedin.linkedin import (LinkedInAuthentication, LinkedInApplication, PERMISSIONS) if __name__ == '__main__': API_KEY = '75ucap9az7urp8' API_SECRET = 'ZfyZ2nA1SEc8RIow' RETURN_URL = 'http://localhost:3000' authentication = LinkedInAuthentication(API_KEY, API_SECRET, RETURN_URL, PERMISSIONS.enums.values()) print authentication.authorization_url application = LinkedInApplication(authentication) authentication.authorization_code = 'AQSQ2RNtXTzC4r7NiV85HSE7Z1ouHrgLuErZatSIzliu2VzHjE7tPZ9f1dztSbQXCIYYyKWWH9mqzyGsJvvYHUVSOjTYFJiwd_vAe-zZ8MNNQf9Tkr8' token_info = authentication.get_access_token() print token_info application = LinkedInApplication(token=token_info) profile_data = application.get_profile() print profile_data
'http://localhost:8888/code', permissions=permissions) #print(authentication.authorization_url) # authentication.authorization_code = code # authentication.state = state # # # print(authentication.get_access_token()) #sys.exit(0) authentication.token = AccessToken( access_token= 'AQXRw7aKOIQpyDS1CqhceHUGssNbPwG-FTH3985dW7Qc0-e-_lqZErrGnntJPzw_KWeH-2V7bzH01UkC1wV_I4qQRJfcXG2MDo38yVCWjtCkvCgKrCsqZIhiBmlzGr0AWtUgOiRV_gy7nMzlAzCEv0R64CRrw1A7jaiRgdCT8sznO6MlC__psorX5xECT45ORyQTieFfE1M2bH9wKgut13Ng9y2WrN0Ja6eeP2ADSlxMUbg04RjAd7z4VndqlFFQv7hddOh3JhOToUCmIcxoWH5qaFOuZ6rgJ27qcZeSTPpPcdlg8ISjtkA4uU85WdavE9wTJ2ElV4eJBYZA5n6NKdTPSie9Lg', expires_in=5183999) app = LinkedInApplication(authentication=authentication) result = app.search_company(selectors=[{ 'companies': ['name', 'universal-name', 'website-url'] }], params={'keywords': 'apple microsoft'}) #result = app.search_profile(selectors=[{'people': ['first-name', 'last-name']}], params={'keywords': 'apple microsoft'}) #app #result = app.get_companies() print(result) # authentication.authorization_code = code # authentication.state = state