gdata.data.PhoneNumber:我如何获得电话号码类型?

时间:2015-11-16 23:19:49

标签: google-api gdata google-api-python-client

使用gdata.data.PhoneNumber课程,我如何获得该电话号码的类型(家庭/商业/手机/等)?

这是我引用的文档:https://gdata-python-client.googlecode.com/hg/pydocs/gdata.data.html#PhoneNumber

1 个答案:

答案 0 :(得分:0)

" rel"属性应该是你要找的。 这是来自this article的示例代码:

# 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实例后,您可以使用https://github.com/google/gdata-python-client/blob/master/tests/gdata_tests/contacts/service_test.py打印每个属性:

print(dir(phone_number))

以下是" rel" s(the built-in dir() function)的列表。我不知道是否所有内容都适用于电话号码,但检查类型可能有用:

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'

那些其他"可以(或者可能应该?)加入对象"标签"属性。