2015-09-01 2 views
1

Я пытаюсь получить имя каждого контакта в фиде контактов Google, используя python, и на основе Retrieve all contacts from gmail using python.Анализ фида контактов Google в Python

social = request.user.social_auth.get(provider='google-oauth2') 
url = 'https://www.google.com/m8/feeds/contacts/default/full' + '?access_token=' + social.tokens + '&max-results=10000' 
req = urllib2.Request(url, headers={'User-Agent' : "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.30 (KHTML, like Gecko) Ubuntu/11.04 Chromium/12.0.742.112 Chrome/12.0.742.112 Safari/534.30"}) 
contacts = urllib2.urlopen(req).read() 
contacts_xml = etree.fromstring(contacts) 
contacts_list = [] 
n = 0 
for entry in contacts_xml.findall('{http://www.w3.org/2005/Atom}entry'): 
    n = n + 1 
    for name in entry.findall('{http://schemas.google.com/g/2005}name'): 
     fullName = name.attrib.get('fullName') 
     contacts_list.append(fullName) 

Я могу получить количество контактов n, но не повезло получения fullName. Любая помощь приветствуется!

ответ

1

В случае, если кто-то нуждается в этом, я нашел решение, чтобы получить имя из Google Contacts кормить:

for entry in contacts_xml.findall('{http://www.w3.org/2005/Atom}entry'): 
    for title in entry.findall('{http://www.w3.org/2005/Atom}title'): 
     name = title.text 
     contacts_list.append(name) 
Смежные вопросы