【发布时间】:2011-03-08 15:29:47
【问题描述】:
我正在尝试访问我的联系人列表中所有条目的组名。给定 href 链接,如何访问组的详细信息?
这是当前的输出:
9 Albert Gandhi 2011-03-07T09:48:19.824Z
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
albert.gandhi@company1.net
Member of group: http://www.google.com/m8/feeds/groups/blah.blah%40blah.com/base/4c8d4c8d8d218d21
但我想要这样的东西:
9 Albert Gandhi 2011-03-07T09:48:19.824Z
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
albert.gandhi@company1.net
Member of group: GroupName
下面是我用来列出联系人提要的代码(主要取自 API 提供的示例)
def PrintFeed(self, feed, ctr=0):
"""Prints out the contents of a feed to the console.
Args:
feed: A gdata.contacts.ContactsFeed instance.
ctr: [int] The number of entries in this feed previously printed. This
allows continuous entry numbers when paging through a feed.
Returns:
The number of entries printed, including those previously printed as
specified in ctr. This is for passing as an argument to ctr on
successive calls to this method.
"""
if not feed.entry:
print '\nNo entries in feed.\n'
return 0
for i, entry in enumerate(feed.entry):
print '\n%s %s %s' % (ctr+i+1, entry.title.text, entry.updated.text)
if entry.content:
print ' %s' % (entry.content.text)
for email in entry.email:
if email.primary and email.primary == 'true':
print ' %s' % (email.address)
# Show the contact groups that this contact is a member of.
for group in entry.group_membership_info:
print ' Member of group: %s' % (group.href)
# Display extended properties.
for extended_property in entry.extended_property:
if extended_property.value:
value = extended_property.value
else:
value = extended_property.GetXmlBlobString()
print ' Extended Property %s: %s' % (extended_property.name, value)
return len(feed.entry) + ctr
【问题讨论】:
-
@gonvaled 从哪里来 'GroupName' 我们在你所显示的字符串中看到你想要作为'Member of Group:'的结果? google.com/m8/feeds/groups/blah.blah%40blah.com/base/… 是 group.href ,据我所知。因此,您必须找到将提供 GroupName 的组属性。还有什么??
-
GroupName 只是一个占位符。应该有真实的组名,例如 Friends、Coworkers 或任何自定义的组名。问题是我不知道如何从组的 href 开始访问该信息。
-
@gonvaled 我们无法知道更多。我试了一下地址,结果是Authorization required Error 401 好像是私人数据库或网站。您希望人们如何从私人场所获取信息?
-
您将无法访问该地址,因为它已被混淆 - 这只是一个示例。该请求应在 gdata api 身份验证上下文中执行。这应该返回有关组的详细信息,但我不知道如何实现。
-
@gonvaled 所以你的代码没有用处。您的问题是关于 gdata 的功能。我没有注意到您的代码中的名称 gdata,尽管它在其中。 gdata 代表 Google 数据吗?