冰恋 发表于 2017-5-5 10:57:16

google contact api 使用 : python获取所有goole联系人

  最近有用程序管理自己联系人的想法,所以学习了一下google contact的api 作为一个起步放出 python 获取所有联系人的代码与大家分享:
  


'''
Created on 2011-4-10
@author: wary
'''
from gdata.contacts.client import ContactsQuery, ContactsClient
def PrintFeed(feed):
for i,entry in enumerate(feed.entry):
print '\n%s %s' % (i+1,entry.title.text)
for email in entry.email:
if email.primary and email.primary == 'true':
print '%s' % (email.address)
for phone_number in entry.phone_number:
print phone_number.to_string(),
print phone_number.uri,

if __name__ == '__main__':
email = 'email@gmail.com'
password ='passwd'
appname = 'wary-contactsSync-1.0'
client = ContactsClient(source = appname)
#登录客户端
client.ClientLogin(email, password, source = client.source)
#设置获取联系人的条件 最长结果 以及排序方式 不设置的话 默认只返回25条数据
query = ContactsQuery()
query.max_results = 1000
query.orderby = 'lastmodified'
#获取联系人
feed = client.GetContacts(q = query)
PrintFeed(feed)
 
页: [1]
查看完整版本: google contact api 使用 : python获取所有goole联系人