我正在努力使用Google API客户端:https://github.com/google/google-api-ruby-client
具体来说,我想使用以下内容通过Google API客户端访问Google通讯录google_contacts_api.rb:https://gist.github.com/lightman76/2357338dcca65fd390e2
我试图这样使用google_contacts_api.rb(x是故意的,实际上是正确的键):
require './lib/google_contacts_api.rb'
auth = User.first.authentications.first
client = OAuth2::Client.new('x', 'x', :site => 'https://accounts.google.com')
oauth2_object = OAuth2::AccessToken.new(client, auth.token)
x = ContactList::GoogleContactsApi.new(client, oauth2_object).all_contacts
Run Code Online (Sandbox Code Playgroud)
这是错误的,undefined method因为#是你的意思吗?gem`
我认为问题是我没有client正确发送,我无法找到任何显示如何创建的文档或示例client.有关如何使其工作的任何建议?
谢谢
ruby ruby-on-rails google-api google-contacts-api google-api-ruby-client
我正在努力让google-api-ruby-client gem按照基本用法示例进行操作:基本用法
require 'google/apis/drive_v2'
Drive = Google::Apis::DriveV2 # Alias the module
drive = Drive::DriveService.new
drive.authorization = ... # See Googleauth or Signet libraries
# Search for files in Drive (first page only)
files = drive.list_files(q: "title contains 'finances'")
files.items.each do |file|
puts file.title
end
Run Code Online (Sandbox Code Playgroud)
我被困的地方是drive.authorization.我已经通过gem omniauth-google-oauth2为用户提供了一个授权令牌.如何在google-api-ruby-client中使用该令牌?
谢谢
我想知道OmniAuth gem使用了哪些提供程序.我试过这个:
OmniAuth::Strategies.constants # a method provided by the standard lib Module class
# => [:Developer, :OAuth, :Twitter]
Run Code Online (Sandbox Code Playgroud)
还有这个:
OmniAuth.strategies.inspect # a method provided by the OmniAuth class, but which has no documentation or comments around it.
# => [OmniAuth::Strategies::OAuth]
Run Code Online (Sandbox Code Playgroud)
我期望(或想要)的答案[:Developer, :Twitter]就像我的测试代码一样,我只是明确地加载了twitter,默认情况下加载了开发人员.
(这就是所有不同的库可以加载正确的东西使它工作,取决于OmniAuth运行的是什么.)
如果有办法让你知道,请告诉我.否则我将是务实的,并从第一个例子中将OAuth从列表中删除.
Ruby是1.9.3,OmniAuth是v1.1.1