【发布时间】:2016-02-18 04:55:49
【问题描述】:
使用 gdata.data.PhoneNumber 类,我如何获取该电话号码的类型(家庭/企业/手机/等)?
这是我引用的文档:https://gdata-python-client.googlecode.com/hg/pydocs/gdata.data.html#PhoneNumber
【问题讨论】:
标签: google-api gdata google-api-python-client
使用 gdata.data.PhoneNumber 类,我如何获取该电话号码的类型(家庭/企业/手机/等)?
这是我引用的文档:https://gdata-python-client.googlecode.com/hg/pydocs/gdata.data.html#PhoneNumber
【问题讨论】:
标签: google-api gdata google-api-python-client
“rel”属性应该是您正在寻找的。 这是来自https://github.com/google/gdata-python-client/blob/master/tests/gdata_tests/contacts/service_test.py的示例代码:
# Create a new entry
new_entry = gdata.contacts.ContactEntry()
new_entry.title = atom.Title(text='Elizabeth Bennet')
new_entry.content = atom.Content(text='Test Notes')
new_entry.email.append(gdata.contacts.Email(
rel='http://schemas.google.com/g/2005#work',
primary='true',
address='liz@gmail.com'))
new_entry.phone_number.append(gdata.contacts.PhoneNumber(
rel='http://schemas.google.com/g/2005#work', text='(206)555-1212'))
new_entry.organization = gdata.contacts.Organization(
org_name=gdata.contacts.OrgName(text='TestCo.'),
rel='http://schemas.google.com/g/2005#work')
它不访问“rel”属性,但它在那里,我发誓:)
一旦获得 PhoneNumer 实例,您就可以使用 the built-in dir() function 打印每个属性:
print(dir(phone_number))
以下是“rel”列表 (https://github.com/google/gdata-python-client/blob/master/src/gdata/data.py)。我不知道是否所有都适用于电话号码,但它可能对检查类型有用:
FAX_REL = 'http://schemas.google.com/g/2005#fax'
HOME_REL = 'http://schemas.google.com/g/2005#home'
HOME_FAX_REL = 'http://schemas.google.com/g/2005#home_fax'
ISDN_REL = 'http://schemas.google.com/g/2005#isdn'
MAIN_REL = 'http://schemas.google.com/g/2005#main'
MOBILE_REL = 'http://schemas.google.com/g/2005#mobile'
OTHER_REL = 'http://schemas.google.com/g/2005#other'
OTHER_FAX_REL = 'http://schemas.google.com/g/2005#other_fax'
PAGER_REL = 'http://schemas.google.com/g/2005#pager'
RADIO_REL = 'http://schemas.google.com/g/2005#radio'
TELEX_REL = 'http://schemas.google.com/g/2005#telex'
TTL_TDD_REL = 'http://schemas.google.com/g/2005#tty_tdd'
WORK_REL = 'http://schemas.google.com/g/2005#work'
WORK_FAX_REL = 'http://schemas.google.com/g/2005#work_fax'
WORK_MOBILE_REL = 'http://schemas.google.com/g/2005#work_mobile'
WORK_PAGER_REL = 'http://schemas.google.com/g/2005#work_pager'
NETMEETING_REL = 'http://schemas.google.com/g/2005#netmeeting'
那些其他“rel”可以(或者应该?)与对象的“label”属性连接。
【讨论】: