Tag: google api

Ruby Google Calendar Integration观看事件/推送通知

以下代码片段打印日历ID的事件,配置了所有日历并尝试在日历上设置观看通知。 一切都有效但手表事件方法。 我收到此错误:apis / core / http_command.rb:212:在`check_status’中:未经授权(Google :: Apis :: AuthorizationError) 这个看起来很奇怪,因为日历和事件检索工作正常。 service = Google::Apis::CalendarV3::CalendarService.new service.client_options.application_name = APPLICATION_NAME service.authorization = authorize # Fetch the next 10 events for the user calendar_id = ‘us7i4kt2to4mpb0b5et1f9f4co@group.calendar.google.com’ response = service.list_events(calendar_id, max_results: 10, single_events: true, order_by: ‘startTime’, time_min: Time.now.iso8601) puts “Upcoming events:” puts “No upcoming events found” if response.items.empty? response.items.each […]

使用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文档或示例。 有关如何使其工作的任何建议? 谢谢

在Rails应用中连接到Google AnalyticsAPI

是否有一个很好的教程:如何在Rails应用程序中与Google AnalyticsAPI进行交互? 我已经找到了这个要点 ,但我不确定这个要点中列出的每一步是否都是必要的。 如果这是一个很好的教程,我可以在哪里下载提到的“key_file”? 我似乎无法在https://code.google.com/apis/console/中找到它。 另外,我在哪里可以找到我的API客户端电子邮件地址/ SERVICE ACCOUNT EMAIL?

cron crawler使用Ruby中的Google API将数据插入Google电子表格的授权问题

我的项目是抓取某些网络数据,并在每天早上9点将它们放入我的Google电子表格中。 它必须获得读写权限的授权。 这就是为什么下面的代码位于顶部。 # Google API CLIENT_ID = blah blah CLIENT_SECRET = blah blah OAUTH_SCOPE = blah blah REDIRECT_URI = blah blah # Authorization_code def get_authorization_code client = Google::APIClient.new client.authorization.client_id = CLIENT_ID client.authorization.client_secret = CLIENT_SECRET client.authorization.scope = OAUTH_SCOPE client.authorization.redirect_uri = REDIRECT_URI uri = client.authorization.authorization_uri Launchy.open(uri) # Exchange authorization code for access token $stdout.write “Enter authorization […]

未创建Rails + Google Calendar API事件

我创建了rails web app。 当用户执行某些操作时,我的应用必须在Google日历中创建新活动。 对于我的任务,我选择服务器到服务器授权。 我写了下一个ruby代码: client = Google::APIClient.new({:application_name => “Rails calendar”, :application_version => “1.0”}) keypath = Rails.root.join(‘config’,’google_secrets.p12′).to_s key = Google::APIClient::PKCS12.load_key(keypath, “notasecret”) # generate request body for authorization client.authorization = Signet::OAuth2::Client.new( :token_credential_uri => ‘https://accounts.google.com/o/oauth2/token’, :audience => ‘https://accounts.google.com/o/oauth2/token’, :scope => ‘https://www.googleapis.com/auth/calendar’, :issuer => ‘***’, :signing_key => key).tap{ |auth| auth.fetch_access_token! } api_method = client.discovered_api(‘calendar’,’v3′).events.insert @meeting_data = { […]

如何从服务帐户谷歌驱动器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 ,它会显示我的空白屏幕。 为什么我无法下载? 我猜,那可能是有许可问题吗? 但范围是正确的,上传成功…

通过Gmail API创建包含收件人的Gmail草稿

我一直试图弄清楚如何自动将收件人添加到使用Gmail API通过其Ruby库创建的草稿电子邮件中。 我可以创建草案而没有任何问题,但设置收件人会给我带来麻烦,我无法找到任何好的示例,显示添加电子邮件特定事物的最佳方法。 使用Google API游乐场并提取已经创建的草稿,看起来结构应该与下面显示的类似,但是无论何时创建草稿,都没有收件人。 @result = client.execute( :api_method => gmail.users.drafts.create, :parameters => { ‘userId’ => “me” }, :body_object => { ‘message’ => { ‘raw’ => Base64.urlsafe_encode64(‘Test Email Message’), ‘payload’ => { ‘headers’ => [ { ‘name’ => “To”, ‘value’ => “John Smith ” } ] } } } )

如何使用OAuth 2.0为Ruby中的google预测API进行授权?

我试图简单地向谷歌的托管模型sample.sentiment发送请求。 我无法弄清楚如何通过谷歌使用Oauth 2.0进行授权,而且我将获得无穷无尽的时间。 如果你可以提供我的代码,这将是有帮助的。 这就是我的工作方式。 client = Google::APIClient.new({:application_name => “CCE”,:application_version => “1.0”} ) plus = client.discovered_api(‘prediction’) # Initialize OAuth 2.0 client client.authorization.client_id = ‘my client id’ client.authorization.client_secret = ‘my client secret’ client.authorization.redirect_uri = ‘my callback url’ client.authorization.scope = ‘https://www.googleapis.com/auth/prediction’ # Request authorization redirect_uri = client.authorization.authorization_uri # Wait for authorization code then exchange for token client.authorization.code […]

使用Ruby中的Google Apps API和服务帐户时出现问题

我在获取用于实例化Drive Service帐户的示例代码时遇到了一些麻烦。 我已按照指示在API控制台中设置服务帐户,并包含“ https://www.googleapis.com/auth/drive ”的范围,但运行此操作会生成以下错误:“授权失败。服务器消息:(Signet :: AuthorizationError)“。 奇怪的是,如果我省略user_email地址,它不会产生错误。 我的目标是能够对组织的驱动器上存储的所有文件进行审核,我的理解是使用服务帐户将获得存储的所有文件的列表。 我是否错过了服务器端的一些特殊设置? require ‘google/api_client’ ## Email of the Service Account # SERVICE_ACCOUNT_EMAIL = ‘@developer.gserviceaccount.com’ ## Path to the Service Account’s Private Key file # SERVICE_ACCOUNT_PKCS12_FILE_PATH = ‘-privatekey.p12’ def build_client(user_email) key = Google::APIClient::PKCS12.load_key(SERVICE_ACCOUNT_PKCS12_FILE_PATH, ‘notasecret’) asserter = Google::APIClient::JWTAsserter.new(SERVICE_ACCOUNT_EMAIL, ‘https://www.googleapis.com/auth/drive’, key) client = Google::APIClient.new client.authorization = asserter.authorize(user_email) return client end […]

在Ruby上访问Google Contacts API

我很难访问Google Contacts API。 首先我尝试了google-api-ruby-client gem,但事实certificate它不支持Contacts API 。 下一个镜头是google_contacts_api gem,但我很难获得oauth_access_token_for_user和oAuth2 gem 。 当遵循oAuth2指令时,我不知道在authorization_code_value和Basic some_password放入什么。 我尝试了以下方法: require ‘oauth2’ client = OAuth2::Client.new(ENV[‘GOOGLE_CLIENT_ID’], ENV[‘GOOGLE_CLIENT_SECRET’], :site => ‘http://localhost:9292’) => #”/oauth/authorize”, :token_url=>”/oauth/token”, :token_method=>:post, :connection_opts=>{}, :connection_build=>nil, :max_redirects=>5, :raise_errors=>true}> client.auth_code.authorize_url(:redirect_uri => ‘http://localhost:9292’) => “http://localhost:9292/oauth/authorize?client_id=blabla.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A9292&response_type=code” token = client.auth_code.get_token(‘authorization_code_value’, :redirect_uri => ‘http://localhost:9292’, :headers => {‘Authorization’ => ‘Basic some_password’}) => Faraday::ConnectionFailed: Connection refused – connect(2) for […]