Tag: 谷歌的API ruby客户端

Google表格API v4 service_account – 禁止:来电者没有权限(Google :: Apis :: ClientError)

Ruby:2.3.1 Rails:5.0.0 我需要通过Google表格API访问和更新我的私人Google表格。 最终,这应该由我的Rails应用程序中的重复后台作业完成。 因此,我在Google云端控制台中设置了服务帐户。 但是要开始使用Google表格API,我创建了一个脚本: require ‘google/apis/sheets_v4’ ENV[“GOOGLE_ACCOUNT_TYPE”] = ‘service_account’ ENV[“GOOGLE_CLIENT_EMAIL”] = ” ENV[“GOOGLE_PRIVATE_KEY”] = “” SCOPE = Google::Apis::SheetsV4::AUTH_SPREADSHEETS authorization = Google::Auth.get_application_default(SCOPE) # Initialize the API service = Google::Apis::SheetsV4::SheetsService.new service.authorization = authorization spreadsheet_id = ” sheet_name = ‘Sheet1’ range = “#{sheet_name}!A2:B” response = service.get_spreadsheet_values(spreadsheet_id, range) puts ‘No data found.’ if response.values.empty? response.values.each do |row| […]

尝试使用YoutubeV3 API创建实时广播时出现“需要登录”错误

我正在尝试使用google-api-ruby-client创建新的广播 YT = Google::Apis::YoutubeV3 client = YT::YouTubeService.new client.key = ‘my-api-key-here’ metadata = { snippet: { title: ‘test’, scheduled_start_time: ‘2018-02-23T14:50:00.000Z’ }, status: { privacy_status: ‘public’ } } part = ‘snippet’ client.insert_live_broadcast(part, metadata, {}) 当我执行此代码时,我收到Error -# [5] pry(main)> CreateYoutubeBroadcast.execute Sending HTTP post https://www.googleapis.com/youtube/v3/liveBroadcasts?key=my-api-key&part=snippet 401 #<HTTP::Message:0x007f8d5356fdc8 @http_header=#<HTTP::Message::Headers:0x007f8d5356fda0 @http_version="1.1", @body_size=0, @chunked=false, @request_method="POST", @request_uri=#, @request_query=nil, @request_absolute_uri=nil, @status_code=401, @reason_phrase=”Unauthorized”, @body_type=nil, @body_charset=nil, […]

google-api-ruby-client当前用户没有足够的权限来执行请求的操作

我使用google-api-ruby-client google-api-ruby-client为我的后端服务器validationandroid inapppurchase代码(见下文): require ‘google/api_client’ require ‘google/api_client/client_secrets’ require ‘google/api_client/auth/installed_app’ API_VERSION = ‘v1.1’ service_account_email = ‘xxx@developer.gserviceaccount.com’ # Email of service account key_file = ‘xxx.p12’ # File containing your private key key_secret = ‘notasecret’ # Password to unlock private key scope_url = ‘https://www.googleapis.com/auth/androidpublisher’ client = Google::APIClient.new( :application_name => ‘Ruby Inapppurchases validate’, :application_version => ‘1.0.0’) key = Google::APIClient::KeyUtils.load_from_pkcs12(key_file, […]

在Google云端硬盘API中接收错误403 – 超出未经身份validation的使用的每日限制。 继续使用需要注册

我正在使用Google Drive API进行ruby,我正在尝试将文件插入用户驱动器。 我可以成功插入文件,但是当我尝试获取文件Self Link时,这是返回的URL https://www.googleapis.com/drive/v2/files/1PxrbKaO2xwOonUO0TB0FO3pkZDnSmRKTvIUmXw0vL6w ,表示我已超出未经身份validation的请求数。 好吧,我很确定我已通过身份validation,因为我遵循了所有教程并且代码几乎相同。 谁知道为什么会这样? 为什么我可以插入文件,但无法查看它的Self Link? 以下是用户允许应用程序进行离线访问后,在驱动器中创建文档的代码: SCOPES = [ ‘https://www.googleapis.com/auth/drive’, ‘https://www.googleapis.com/auth/userinfo.email’, ‘https://www.googleapis.com/auth/userinfo.profile’ ] class DriveAuthenticator def self.create_document(user, title, description, parent_title, user_array) client = DriveAuthenticator.initiate_client if user.google_id.present? if DriveAuthenticator.authenticate_client client, user parent_id = get_parent_id client, parent_title file_data = insert_empty_file client, title, description, DOCUMENT_MIME_TYPE, parent_id return file_data.selfLink end end end private […]

Ruby实时谷歌分析API

我试图通过google-api-ruby-client获得activeVisitors。 客户端在此处列出了实时谷歌分析API文档,但我在文档中没有看到任何关于将其用于实时API的文档。 我看到函数discovered_api但是我没有看到API名称的posisble参数列表。 常规分析API示例: # Get the analytics API analytics = client.discovered_api(‘analytics’,’v3′) 有谁知道如何使用此客户端来获得实时活跃的访问者? 这是我尝试使用的代码: require ‘google/api_client’ require ‘date’ # Update these to match your own apps credentials service_account_email = ‘xxxxxxxxxxxxx@developer.gserviceaccount.com’ # Email of service account key_file = ‘/path/to/key/privatekey.p12’ # File containing your private key key_secret = ‘notasecret’ # Password to unlock private key profileID = […]

使用ruby gmail api v0.9发送电子邮件

有没有人有一个简单的例子,说明如何使用v0.9 API从头开始发送电子邮件。 只想要一个发送以下内容的例子: m = Mail.new( to: “test1@test.com”, from: “test2@test.com”, subject: “Test Subject”, body:”Test Body”) 现在要创建需要发送的消息对象,我们可以使用: msg = Base64.urlsafe_encode64 m.to_s 然后尝试发送(其中message_object = msg): client = Google::Apis::GmailV1::GmailService.new #Appropriately authorised client.send_user_message(“me”, message_object) 客户端需要RFC822兼容的编码字符串,以上应该是。 我试过了: message_object = msg => Google::Apis::ClientError: invalidArgument: ‘raw’ RFC822 payload message string or uploading message via /upload/* URL required message_object = raw:msg =>ArgumentError: unknown […]

如何授权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 我被困的地方是drive.authorization 。 我已经通过gem omniauth-google-oauth2为用户提供了一个授权令牌。 如何在google-api-ruby-client中使用该令牌? 谢谢

使用Google API Client,如何创建客户端

我正在努力使用Google API客户端: https : //github.com/google/google-api-ruby-client 具体来说,我想使用以下google_contacts_api.rb通过Google API客户端访问Google通讯录: 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 这是错误的undefined method得到’为#你的意思? gem` 我相信问题是我没有正确发送client ,我无法找到任何显示如何创建client文档或示例。 有关如何使其工作的任何建议? 谢谢

如何在没有默认凭据文件的情况下授权Google服务帐户?

我有一个Google服务帐户 ,我的应用可以使用该帐户从Google Analytics中检索数据。 当我创建帐户时,我下载了一个client_secrets文件,其中包含通过OAuth授权的所有必要信息,并且我根据Google的文档在名为GOOGLE_APPLICATION_CREDENTIALS的环境变量中记录了此文件的路径。 我现在可以得到这样一个经过身份validation的客户端: authorization = Google::Auth.get_application_default(scopes) 此方法从文件中读取凭证,该凭证在本地运行,但我的应用程序托管在Heroku上,无法进行文件存储。 文档说明我可以提供此文件(不能),在官方Google服务上运行我的应用程序(不会),或者遇到错误。 如何在没有client_secrets文件的情况下validation我的服务帐户?

如何从服务帐户谷歌驱动器api下载文件?

你好谷歌黑客! 我正在使用Drive Service应用程序并成功上传文件,如下所示: require ‘googleauth’ require ‘google/apis/drive_v2’ Drive = Google::Apis::DriveV2 upload_source = “/User/my_user_name/hacking.txt” drive = Drive::DriveService.new # Drive::AUTH_DRIVE is equal to https://www.googleapis.com/auth/drive drive.authorization = Google::Auth.get_application_default([Drive::AUTH_DRIVE]) file = drive.insert_file({title: ‘hacking.txt’}, upload_source: upload_source) file有很多属性,比如: download_url 但是当我尝试在浏览器中打开这个download_url ,它会显示我的空白屏幕。 为什么我无法下载? 我猜,那可能是有许可问题吗? 但范围是正确的,上传成功…