我正在努力使用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服务帐户,我的应用可以使用该帐户从Google Analytics中检索数据.
当我创建帐户时,我下载了一个client_secrets文件,其中包含通过OAuth授权的所有必要信息,我在一个环境变量中记录了该文件的路径,该变量GOOGLE_APPLICATION_CREDENTIALS根据Google的文档进行了调用.
我现在可以得到这样一个经过身份验证的客户端:
authorization = Google::Auth.get_application_default(scopes)
Run Code Online (Sandbox Code Playgroud)
此方法从文件中读取凭据,该凭据在本地运行,但我的应用程序托管在Heroku上,无法进行文件存储.
文档说明我可以提供此文件(不能),在官方Google服务上运行我的应用程序(不会),或者遇到错误.
如何在没有该client_secrets文件的情况下验证我的服务帐户?
我正在开发具有社交授权的rails app.Facebook和Twitter登录工作正常,但谷歌有点奇怪......
我的谷歌初始化程序:
provider :google_oauth2, OAUTH_CONFIG[:google_api_key], OAUTH_CONFIG[:google_api_secret], {
:access_type => 'offline',
:prompt => 'consent',
:scope => 'userinfo.email, userinfo.profile, youtube.readonly'
}
Run Code Online (Sandbox Code Playgroud)
我在点击Google登录时看到的错误:
Faraday::Error::ConnectionFailed
SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
/Users/bmalets/.rvm/rubies/ruby-2.1.4/lib/ruby/2.1.0/net/http.rb:920:in `connect'
/Users/bmalets/.rvm/rubies/ruby-2.1.4/lib/ruby/2.1.0/net/http.rb:920:in `block in connect'
/Users/bmalets/.rvm/rubies/ruby-2.1.4/lib/ruby/2.1.0/timeout.rb:76:in `timeout'
/Users/bmalets/.rvm/rubies/ruby-2.1.4/lib/ruby/2.1.0/net/http.rb:920:in `connect'
/Users/bmalets/.rvm/rubies/ruby-2.1.4/lib/ruby/2.1.0/net/http.rb:863:in `do_start'
/Users/bmalets/.rvm/rubies/ruby-2.1.4/lib/ruby/2.1.0/net/http.rb:852:in `start'
/Users/bmalets/.rvm/rubies/ruby-2.1.4/lib/ruby/2.1.0/net/http.rb:1369:in `request'
faraday (0.8.8) lib/faraday/adapter/net_http.rb:75:in `perform_request'
faraday (0.8.8) lib/faraday/adapter/net_http.rb:38:in `call'
faraday (0.8.8) lib/faraday/request/url_encoded.rb:14:in `call'
faraday (0.8.8) lib/faraday/connection.rb:253:in `run_request'
oauth2 (0.8.1) lib/oauth2/client.rb:88:in `request'
oauth2 (0.8.1) lib/oauth2/client.rb:131:in `get_token'
oauth2 (0.8.1) lib/oauth2/strategy/auth_code.rb:29:in `get_token'
Run Code Online (Sandbox Code Playgroud)
SSL证书有什么问题?请帮忙
在谷歌搜索结果中,我看到许多类似的答案 - …
ruby-on-rails oauth google-api google-api-client google-api-ruby-client
鉴于用户(Google Play的帐户所有者)已使用正确的范围对我的应用程序(Google App Engine的服务帐户)进行了身份验证...
Google API中是否有返回dev_acc用于访问其Play商店开发者帐户的参数的端点?
具体我想检索它以访问https://play.google.com/apps/publish/?dev_acc=DEV_ACC_ID以gs://pubsite_prod_rev_DEV_ACC_ID/
编程方式找到的以下URI
或云存储桶?
或者,列出他/她拥有的所有云存储桶?(包括gs://pubsite_prod_rev_DEV_ACC_ID/水桶)
google-api-client google-cloud-storage google-play google-api-ruby-client google-play-developer-api
我正在努力让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中使用该令牌?
谢谢
我想update和delete使用视频的YouTube的API V3使用的OAuth2认证通过google-api-client (0.6.4)红宝石的宝石.但是,当我尝试执行这两个操作中的任何一个时,我看到以下错误消息:
Google::APIClient::ClientError: Insufficient Permission
Run Code Online (Sandbox Code Playgroud)
下面是奇怪的事情:使用完全相同的认证过程与update和delete,我可以insert(上载)成功,没问题!所以,我不认为这是我的身份验证设置的问题,但我的代码中的其他地方.
scope在任何这些操作中,我的读写总是相同的:
https://www.googleapis.com/auth/youtube https://www.googleapis.com/auth/youtube.upload
Run Code Online (Sandbox Code Playgroud)
并根据API文档,该空间分隔组作用域应包括insert,update和delete行动.
我client_id,client_secret,refresh_token始终是所有这些行动也一样-所以,这不能成为问题,或者,可以吗?请注意,我的程序access_token在到期时会自动获取新内容,因此,我不相信这就是问题所在.
为了比较,这是我的insert(上传)代码的样子(这是有效的):
# Auth stuff, then...
@client.execute!(
:api_method => @youtube.videos.insert,
:body_object => body,
:media => Google::APIClient::UploadIO.new(file_path, 'video/*'),
:parameters => {
'uploadType' => 'multipart',
:part => body.keys.join(','),
}
)
Run Code Online (Sandbox Code Playgroud)
这是我的delete代码看起来像(这失败): …
我正在尝试模拟一些使用google-api-ruby-client的方法来进行一些测试,而无需实际调用api。身份验证以及客户端和活动方法取自github页上的示例(请参见上面的链接),这就是为什么我在这里跳过了。
该示例中的方法如下:
def activities
result = client.execute(
:api_method => plus.activities.list,
:parameters => {'collection' => 'public', 'userId' => 'me'}
)
return result.data
end
Run Code Online (Sandbox Code Playgroud)
我以前曾尝试对客户端方法(甚至与execute链接)进行存根处理,但是这导致了对oauth的授权请求,gem在其下使用了加号,然后在plus.activities.list方法中使用了模拟。有没有一种方法可以直接模拟client.exectute以在跳过整个链时返回有用的东西?
我正在开发一个使用 Google API(自定义搜索引擎)的 Ruby 应用程序。它与公共 API 访问密钥配合得很好。
我刚刚将互联网升级到 Uverse,突然 Google API 停止工作。我发现问题出在IP地址上。我的 Uverse 调制解调器使用 IPv6。
不幸的是,Google Developer Public API 访问密钥似乎只接受 IPv4 地址,因此当我尝试添加 IPv6 地址时,我收到错误消息:“IP 地址无效”。
有人能够让它发挥作用吗?如果可以避免的话,我宁愿不实现 oAuth。
在 rails 4 应用程序中使用较新的 google-api-ruby-client 发送 gmail。
require 'google/apis/gmail_v1'
Gmail = Google::Apis::GmailV1
class MailService
def initialize(params)
@params = params
end
def call
message = Gmail::Message.new
service = Gmail::GmailService.new
message.raw = (redacted)
service.request_options.authorization = current_user.token.fresh_token
result = service.send_user_message(current_user.email, message)
end
end
Run Code Online (Sandbox Code Playgroud)
这是调用 API 的结果:
Sending HTTP post https://www.googleapis.com/gmail/v1/users/me/messages/send?
200
#<Hurley::Response POST https://www.googleapis.com/gmail/v1/users/me/messages/send == 200 (63 bytes) 858ms>
Success - #<Google::Apis::GmailV1::Message:0x007fc9cf9b52dd
@id="15096369c05cdb1d",
@thread_id="15096369c05cdb1d">
Run Code Online (Sandbox Code Playgroud)
原始消息从 API Explorer 发送没有问题,但是当从我的应用程序执行时,我的收件箱中收到一封退回电子邮件。在上面的示例中,编辑后的示例是一个有效的 RFC 2822 格式的 base-64 url 安全字符串,而 fresh_token 代表当前用户的 oauth2 访问令牌。
查看退回的邮件
Bounce <nobody@gmail.com>
2:43 PM …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 gmail API 发送电子邮件。正如您在下面看到的,我的 Ruby 代码在没有附件的情况下运行良好:
client = google_client user_id
token = Token.find_by_user_id(user_id)
access_token = token.access_token
gmail = Google::Apis::GmailV1::GmailService.new
gmail.authorization = client
message = Mail.new
message.date = Time.now
message.subject = 'Supertram p'
message.body = "<p>Hi Alex, how's life?</p>"
message.content_type = 'text/html'
message.from = self.email
message.to = 'email_name@gmail.com'
msg = message.encoded
message_object = Google::Apis::GmailV1::Message.new(raw:message.to_s)
gmail.send_user_message('me', message_object)
Run Code Online (Sandbox Code Playgroud)
我能够以 html 格式成功发送电子邮件。我的问题是如何将文件附加到此消息?
client = google_client user_id
token = Token.find_by_user_id(user_id)
access_token = token.access_token
gmail = Google::Apis::GmailV1::GmailService.new
gmail.authorization = client
message = Mail.new
message.date = Time.now …Run Code Online (Sandbox Code Playgroud) ruby ×6
google-api ×4
api ×2
gmail-api ×2
oauth ×2
google-play ×1
heroku ×1
ipv6 ×1
omniauth ×1
rspec ×1
youtube ×1
youtube-api ×1