programmatically log into Yahoo/MSN(Hotmail) using python Django code and get the contact list?
-
29-09-2019 - |
Question
Is there a way to programmatically log into Yahoo!, providing email id and password as inputs, and fetch the user's contacts?
I've achieved the same thing with Gmail, using BeautifulSoup.py
Yahoo Address book API provides BBAuth, which requires the user to be redirected to Yahoo login page. But I'm looking for a way to authenticate the user with Yahoo without the redirection. I have tried this : http://pypi.python.org/pypi/ContactGrabber/0.1
but I am getting this Error:
Warning (from warnings module): File "C:\Python26\lib\site-packages\contactgrabber-0.1-py2.6.egg\contactgrabber\base.py", line 31
RuntimeWarning: tempnam is a potential security risk to your program
Invalid UserID/Password
Exception WindowsError: (2, 'The system cannot find the file specified', 'C:\DOCUME~1\sjain\LOCALS~1\Temp\2') in > ignored
Solution
I solved this problem by using Urllib here is the code :
LoginUrl = "https://login.yahoo.com/config/login?" ExportUrl = "http://address.yahoo.com/"
def import_yahoo_contacts(login,passwd):
try :
form_data = {'login' : login, 'passwd' : passwd}
jar = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar))
form_data = urllib.urlencode(form_data)
resp = opener.open(LoginUrl, form_data)
resp = opener.open(ExportUrl)
page = resp.read()
index = page.find('InitialContacts')
startjson = page.index('[',index)
endjson = page.index(']',index)
Jsondata = page[startjson:endjson+1]
user_contacts = []
data =json.JSONDecoder().decode(Jsondata)
for r in data:
userfriends = []
userfriends.append(r.get('contactName'))
userfriends.append(r.get('email'))
user_contacts.append(userfriends)
except:
return []
return user_contacts
This really work for me :)
OTHER TIPS
You could write one or just use Pinax. Pinax is a collection of tools built on top of Django. They have a application which imports contact imfo (from vCard, Google or Yahoo).
I suggest you use this as you don't have to maintain it plus to avoid reinventing the cycle.