google_contacts_api - #<String:0x007fce71ad54e8> 的未定义方法 `get' 您是说吗? gem

google_contacts_api - undefined method `get' for #<String:0x007fce71ad54e8> Did you mean? gem

我正在努力使用 google_contacts_api:https://github.com/aliang/google_contacts_api

我在user.rb中有以下代码:

google_contacts_user = GoogleContactsApi::User.new(self.authentications.first.token)
@x = google_contacts_user.contacts

self.authentications.first.token 是通过 omniauth-google-oauth2 存储的令牌。

问题是,这是错误的:

undefined method `get' for #<String:0x007fce71ad54e8> Did you mean? gem

我做错了什么?

先安装oauth2

 gem install oauth2

然后从令牌字符串创建一个 Oauth2AccessToken 实例

 oauth2_object = OAuth2::AccessToken.new(self.authentications.first.token)

现在应该可以将此 Oauth2AccessToken 与 GoogleContacts 一起使用 gem:

 GoogleContactsApi::User.new(oauth2_object)

我基于 gem 的文档

You need to pass to the GoogleContactsApi::User constructor one of the following two objects:

an OAuth::AccessToken from the oauth-ruby gem an OAuth2::AccessToken from the oauth2 gem