GithubHelp home page GithubHelp logo

linkedin's Introduction

#Overview Here's another library based on the LinkedIn API, OAuth and JSON responses.

Hope this documentation explains everything you need to get started. Any questions feel free to email me or inbox me.

#Install through pip...

pip install linkedin

If linkedin is already installed, pass -I to your install:

pip install -I linkedin

#Import LinkedIn library

from linkedin import *

#Authorization URL

Get an authorization url for your user

l = LinkedinAPI(api_key='*your app key*',
              api_secret='*your app secret*',
              callback_url='http://www.example.com/callback/',
              permissions=["r_network"])

auth_props = l.get_authentication_tokens()
auth_url = auth_props['auth_url']

#Store this token in a session or something for later use in the next step.
oauth_token_secret = auth_props['oauth_token_secret']

print 'Connect with LinkedIn via: %s' % auth_url

If you leave callback_url blank, you can get the oauth_verifier from the web browser. It is a five-digit integer.

The permissions parameter is optional. It can be a list or string. The list of permissions is in the LinkedIn API documentation.

Once you click "Allow" be sure that there is a URL set up to handle getting finalized tokens and possibly adding them to your database to use their information at a later date. \n\n'

#Handling the callback

# In Django, you'd do something like
# oauth_token = request.GET.get('oauth_token')
# oauth_verifier = request.GET.get('oauth_verifier')

oauth_token = *Grab oauth token from URL*
oauth_verifier = *Grab oauth verifier from URL*

#Initiate the LinkedIn class in your callback.
l = LinkedinAPI(api_key='*your app key*',
              api_secret='*your app secret*',
              oauth_token=oauth_token,
              oauth_token_secret=session['linkedin_session_keys']['oauth_token_secret'])

authorized_tokens = l.get_access_token(oauth_verifier)

final_oauth_token = authorized_tokens['oauth_token']
final_oauth_token_secret = authorized_tokens['oauth_token_secret']

# Save those tokens to the database for a later use?

#Getting some user information, search results, network updates.

# Get the final tokens from the database or wherever you have them stored

l = LinkedinAPI(api_key = '*your app key*',
              api_secret = '*your app secret*',
              oauth_token=final_tokens['oauth_token'],
              oauth_token_secret=final_tokens['oauth_token_secret'])

# Get your profile information (first name, last name)
profile = l.get('people/~', fields='first-name,last-name')
print profile

# Get search results
search = l.get('people-search', params={'keywords':'Hacker'})
print search

# Get your network updates
feed = l.get('people/~/network/updates')
print feed

POST a network update

share_content = { 
       "comment": "Posting from the API using JSON", 
       "content": { 
               "title": "A title for your share", 
               "submitted-url": "http://www.linkedin.com", 
               "submitted-image-url": "http://lnkd.in/Vjc5ec" 
       }, 
       "visibility": { 
               "code": "anyone" 
       } 
}

share_update = l.post('people/~/shares', params=share_content)
print share_update

linkedin's People

Contributors

michaelhelmick avatar paulschreiber avatar egonzalez777 avatar rossdeane avatar

Watchers

Mahdi Yusuf avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.