Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/52.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails google\u contacts\u api-未定义的方法“get”是什么意思?宝石_Ruby On Rails_Ruby_Ruby On Rails 5_Google Contacts Api - Fatal编程技术网

Ruby on rails google\u contacts\u api-未定义的方法“get”是什么意思?宝石

Ruby on rails google\u contacts\u api-未定义的方法“get”是什么意思?宝石,ruby-on-rails,ruby,ruby-on-rails-5,google-contacts-api,Ruby On Rails,Ruby,Ruby On Rails 5,Google Contacts Api,我正在使用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 me

我正在使用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)
现在应该可以在GoogleContacts gem中使用此Oauth2AccessToken:

 GoogleContactsApi::User.new(oauth2_object)
我是根据gem的文件做的

您需要向GoogleContactsApi::用户构造函数传递 以下两个对象:

OAuth ruby gem中的OAuth::AccessToken是OAuth2::AccessToken 来自oauth2 gem


你检查过谷歌联系人的等级了吗?它的类不是String类,对吗?我不确定我在跟踪。我做错了什么?你试过调试google\u contacts\u用户吗?可能self.authentications.first.token是字符串,而不是OAuth2::AccessToken对象required@AnApprentice这一切都在gem的文档中。有关如何获取此对象的详细信息,请参阅各自的文档。感谢@joel_blum,刚刚尝试了一下,oauth2_对象行出错,参数数量错误,给定1,预期为2。。3@AnApprentice你明白了吗?我将编辑我的答案以备将来参考