我很努力地访问Google Contacts API。首先我尝试了google-api-ruby-client gem
,但事实证明它不支持Contacts API
。如何在ruby中访问Google Contacts API
下一张照片是google_contacts_api gem。我使用oauth2
来访问验证密钥(Getting authentication token guide question)。但是,将令牌正确传递给API后,会产生错误。
`<main>': undefined method `[]' for #<GoogleContactsApi::GroupSet:0x000000039fcad8>` (NoMethodError).
这是我的代码。
# get token using oauth2 gem, and use it below in the google_contacts_api.
google_contacts_user = GoogleContactsApi::User.new(token)
contacts = google_contacts_user.contacts
groups = google_contacts_user.groups
# group methods
group = groups[0]
group.contacts
puts group.contacts
# contact methods
puts contacts.count
puts groups.count
contact = contacts[0]
contact.primary_email
contact.emails
我在做什么错?
UPDATE:
由于@alvin
建议现在运转。但小组联系人没有被打印出来。相反,它是印刷#<GoogleContactsApi::ContactSet:0x000000020e49d8>
。实例:
#<GoogleContactsApi::ContactSet:0x000000020e49d8>
#<GoogleContactsApi::ContactSet:0x0000000504aec0>
#<GoogleContactsApi::ContactSet:0x0000000518dfd0>
#<GoogleContactsApi::ContactSet:0x000000052d9290>
#<GoogleContactsApi::ContactSet:0x000000054280d8>
#<GoogleContactsApi::ContactSet:0x0000000558c2f8>
#<GoogleContactsApi::ContactSet:0x00000005746eb8>
#<GoogleContactsApi::ContactSet:0x000000058a3ea0>
我怎样才能打印组联系人:这里是什么是这个代码
groups = google_contacts_user.groups
# group methods
groups.each do |group|
group_contacts = group.contacts
puts group_contacts
end
输出打印?