Friday, 27 February 2015

How to do Linkedin people search api in python?



I am trying to find people in linkdein with their profile data using keywords.....


I follow below document.


http://ift.tt/1nIf7sF


The People Search API returns information about people. It lets you implement most of what shows up when you do a search for "People" in the top right box on LinkedIn.com. You can get more information from here.



application.search_profile(selectors=[{'people': ['first-name', 'last-name']}], params={'keywords': 'apple microsoft'})

# Search URL is http://ift.tt/1wufHTN

{u'people': {u'_count': 10,
u'_start': 0,
u'_total': 2,
u'values': [
{u'firstName': u'John', u'lastName': 'Doe'},
{u'firstName': u'Jane', u'lastName': u'Doe'}
]}}


Below code I tried. I am getting my profile details. But I want to search people based on keywords. application.search_profile function is giving me error.


People_search python document I searched but I couldn't find.



from linkedin import linkedin
from oauthlib import *


CONSUMER_KEY = 'XXXXX'
CONSUMER_SECRET = 'XXXXX'
USER_TOKEN = 'XXXXX'
USER_SECRET = 'XXXXX'
RETURN_URL = 'http://localhost:8000'

authentication = linkedin.LinkedInDeveloperAuthentication(CONSUMER_KEY, CONSUMER_SECRET,
USER_TOKEN, USER_SECRET,
RETURN_URL, linkedin.PERMISSIONS.enums.values())


application = linkedin.LinkedInApplication(authentication)

g = application.get_profile()
print g

Output : {u'lastName': u'Gandhi', u'siteStandardProfileRequest': {u'url': u'http://ift.tt/1zljAVA'}, u'id': u'izHKd17BFS', u'firstName': u'Karamchand'}


application.search_profile(selectors=[{'people': ['first-name', 'last-name']}], params={'keywords': 'apple microsoft'})


while running I am getting below error.

Traceback (most recent call last):
File "E:/Linkedin Scraping/Linkedin", line 22, in <module>
application.search_profile(selectors=[{'people': ['first-name', 'last-name']}], params={'keywords': 'apple microsoft'})
File "C:\Python27\lib\site-packages\linkedin\linkedin.py", line 189, in search_profile
raise_for_error(response)
File "C:\Python27\lib\site-packages\linkedin\utils.py", line 63, in raise_for_error
raise LinkedInError(message)
LinkedInError: 403 Client Error: Forbidden: Unknown Error


And I also tried in rest console. http://ift.tt/1wufKik.


I want all 37934 result and I wanted to store all this result in csv? There I am getting result like this.



<?xml version="1.0" encoding="UTF-8"?>
<people-search>
<people total="37934" count="10" start="0">
<person>
<first-name>Srinivas</first-name>
<last-name>Manam</last-name>
<headline>Sr.Manager - Client Engagement</headline>
<industry>Information Technology and Services</industry>
</person>
<person>
<first-name>*Anand</first-name>
<last-name>Kumar (Andy)*</last-name>
<headline>Assistant Manager - Client Engagement at Magna Infotech Ltd</headline>
<industry>Information Technology and Services</industry>
</person>
<person>
<first-name>Kailash</first-name>
<last-name>Kulkarni.</last-name>
<headline>Manager - IT Staffing Business Development & Delivery</headline>
<industry>Computer Software</industry>
</person>
<person>
<first-name>Ramesh</first-name>
<last-name>A</last-name>
<headline>Asst.Manager- Client Engagement (TAG)</headline>
<industry>Human Resources</industry>
</person>
</people-search>


How to get all 37934 result and store all this result in csv? I am new to python. I am facing difficulties on using this?


No comments:

Post a Comment