Skip to content Skip to sidebar Skip to footer

Getting Oauth Access Token For Linkedin Using Python-linkedin Library

I'm trying to get the LinkedIn user access token using python-linkedin library with the following code. It's giving me access code but not directing to else part after getting the

Solution 1:

I know how to connect doing it step by step, I allways use the OAuth steps and it works for me, tested for XING and Linkedin:

from rauth import OAuth1Service
import webbrowser

CLIENT_ID = 'your client ID'
CLIENT_SECRET = 'your client secret'
RETURN_URL = "http://localhost:8000"
BASE_URL = 'https://api.linkedin.com'
AUTHORIZATION_URL = BASE_URL +'/uas/oauth/authenticate'
REQUEST_TOKEN_URL = BASE_URL +'/uas/oauth/requestToken'
ACCESS_TOKEN_URL = BASE_URL + '/uas/oauth/accessToken'

linkedin = OAuth1Service(
                    name='linkedin',
                    consumer_key=CLIENT_ID,
                    consumer_secret=CLIENT_SECRET,
                    request_token_url=REQUEST_TOKEN_URL,
                    access_token_url=ACCESS_TOKEN_URL,
                    authorize_url=AUTHORIZATION_URL,
                    base_url=BASE_URL)

token, token_secret = linkedin.get_request_token(
    method='GET',
    params={'oauth_callback': 'oob'})

url = linkedin.get_authorize_url(token)
webbrowser.open(url)

pin = raw_input('PIN:')

session = linkedin.get_auth_session(
    token,
    token_secret,
    method='POST',
    data={'oauth_verifier': pin})

Now, you have a variable called 'session' which allows to handle GET, POST and PUT requests. For an instance, that is for Xing, I didn´t try it with Linkedin but it should be something like:

#Find all IDs from your contacts list    
search = "/v1/users/me/contact_ids"
res_ids = session.get(search,params={'format':'json'})
res_ids = res_ids.json()
print res_ids

# PUT a new webpage in your profil
res = session.put(
 '/v1/users/me/web_profiles/homepage',
 {'url[]': 'http://stackoverflow.com/questions/25183197'}
)

Post a Comment for "Getting Oauth Access Token For Linkedin Using Python-linkedin Library"