Пример #1
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/")
Пример #2
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})
Пример #3
0
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)
Пример #4
0
    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")
Пример #5
0
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)
Пример #6
0
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)
Пример #7
0
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)
Пример #8
0
    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)
Пример #9
0
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)
Пример #10
0
Файл: bio.py Проект: jvanz/torre
def get_linkedin_authurl(linkedinid):
    API_KEY = environ.get('LINKEDIN_API_KEY')
    API_SECRET = environ.get('LINKEDIN_API_SECRET')
    RETURN_URL = 'http://localhost:5000/linkedin/authorized'
    authentication = LinkedInAuthentication(
        API_KEY, API_SECRET, RETURN_URL,
        [PERMISSIONS.BASIC_PROFILE, PERMISSIONS.EMAIL_ADDRESS])
    url = authentication.authorization_url
    state = parse_qs(url)['state'][0]
    cache[state] = authentication
    return url
Пример #11
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 ''
Пример #12
0
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
Пример #13
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 ''
Пример #14
0
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)
Пример #15
0
# insert your application KEY and SECRET

API_KEY = "819b9ld1jymobk"
SECRET_KEY = "sBPyr2wY3OWWI8i3"

import webbrowser

from linkedin.linkedin import LinkedInAuthentication

li = LinkedInAuthentication(API_KEY, SECRET_KEY)

token = li.getRequestToken(None)

# prompt user in the web browser to login to LinkedIn and then enter a code that LinkedIn gives to the user

auth_url = li.getAuthorizeUrl(token)
webbrowser.open(auth_url)
validator = input("Enter token: ")
access_token = li.getAccessToken(token, validator)

# list all connections

connections = li.connections_api.getMyConnections(access_token)

print("number of connections:{} ".format(len(connections)))
for c in connections:
    print("{}  {}".format(c.firstname, c.lastname))
Пример #16
0
from linkedin.linkedin import (LinkedInAuthentication, LinkedInApplication,
                               PERMISSIONS)

if __name__ == '__main__':
    API_KEY = 'wFNJekVpDCJtRPFX812pQsJee-gt0zO4X5XmG6wcfSOSlLocxodAXNMbl0_hw3Vl'
    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)
    application = LinkedInApplication(authentication)
Пример #17
0
from linkedin.linkedin import (LinkedInAuthentication, LinkedInApplication,
                               PERMISSIONS)

if __name__ == '__main__':

    CLIENT_ID = '77ptq4iasj89wa'
    CLIENT_SECRET = 'XB2vH79xARyCuLmJ'
    RETURN_URL = 'http://localhost:8080/code/'

    authentication = LinkedInAuthentication(CLIENT_ID,
                                            CLIENT_SECRET,
                                            RETURN_URL,
                                            permissions=['r_basicprofile'])

    # Note: edit permissions according to what you defined in the linkedin
    # developer console.

    # Optionally one can send custom "state" value that will be returned from
    # OAuth server 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)
    application = LinkedInApplication(authentication)
Пример #18
0
# ============ Authorization Code ============ #
# If not used, please set its value to: None
AUTH_CODE = None
# AUTH_CODE     = "##############################################################################################################################################################"

# Set it correctly or assign it to: None
AUTH_TOKEN = None

code = """AQQJjJM3UvkiHidbNQlkLooyxBN88y0nCferoT1_-PNWPhUtQ6IxCfAEghY1uGcL2J26BS6pnp6R9LVffTjZw-ppbR-mkzN4g8EOhsC0xLeNTCX3MYTplDxMUjkzf0QX_loaBznULxmhowpto2CZnON7jXZ2ng"""
state = "4762936a29becfae6fec5d12459b94cc"

#access_token = """AQWwXpwhaVmiFVbEpSnUpxsc6IlobsU9qPnjnBrpMFV-vgB93hawth6lRKBgO2KwO9TOWsErQPz5W7km6lgvn2orG69zCfFuq7OyWsRnHt9m7pLhsfYEGPEVxOsoobqExxW18NhyjAvy5hZj-O_DSdl4TFtKMOCDEnQ8B6GGLua0fClioafjhCBT5MOApuFj0D9tFS42Mlnj8JMhY4b49p6rJhMBm4JjC4hTnFCC4wUW9uVyClMU2Uth0UDx0DqCvHNOYWMeMX9dDmYvLaCEMkFXUwC5rAX5aKuSPQgJfS7NM4SK4nnnDoy0yePMx_y4Vt1QTtjquwcaP824Ahco86Yzo1gLrQ"""

authentication = LinkedInAuthentication(CLIENT_ID,
                                        CLIENT_SECRET,
                                        '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)
Пример #19
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


Пример #20
0
 def __init__(self, authentication=None, token=None):
     assert authentication or token, 'Either authentication instance or access token is required'
     self.authentication = authentication
     if not self.authentication:
         self.authentication = LinkedInAuthentication('', '', '')
         self.authentication.token = AccessToken(token, None)
Пример #21
0
from linkedin.linkedin import (LinkedInAuthentication, LinkedInApplication,
                               PERMISSIONS)

if __name__ == '__main__':

    CLIENT_ID = '<Your Client ID>'
    CLIENT_SECRET = '<Your Client secret>'
    RETURN_URL = 'http://localhost:8080/code/'

    authentication = LinkedInAuthentication(CLIENT_ID,
                                            CLIENT_SECRET,
                                            RETURN_URL,
                                            permissions=[
                                                'r_basicprofile',
                                                'r_emailaddress',
                                                'rw_company_admin', 'w_share'
                                            ])

    # Note: edit permissions according to what you defined in the linkedin
    # developer console.

    # Optionally one can send custom "state" value that will be returned from
    # OAuth server 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)
    application = LinkedInApplication(authentication)