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 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})
def convert_v3(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', '').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] headers = {'auth': token} r = requests.get( 'https://api.linkedin.com/v2/me?oauth2_access_token=' + access_token[0], headers=headers) print r.text return ''
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