Beispiel #1
0
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())
Beispiel #2
0
   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)
Beispiel #3
0
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 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})
Beispiel #5
0
    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'] )            
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