예제 #1
0
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})
예제 #2
0
파일: views.py 프로젝트: Reinaesaya/munchee
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/")
예제 #3
0
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 ''
예제 #4
0
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 ''
예제 #5
0
class LinkedInWrapper(object):
    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)
예제 #6
0
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