Tag: google api

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, […]

403尝试获取Google Analytics数据时权限不足错误

我正在开发RoR应用程序,允许用户使用Google帐户登录并从他的某个分析帐户下载/上传报告数据。 我使用omn​​iauth-google-oauth2 gem进行授权,使用Google帐户和google-api-client与Google Analytics进行互动。 问题是,当我尝试使用analytics.management.accounts.list方法获取帐户列表时,将google令牌作为授权参数之一传递,GA会响应403 Insufficient permissions错误。 我想,我必须让用户在授权过程中阅读Google Analytics数据。 我怎样才能做到这一点? 我已经阅读了很多相关问题,但没有找到解决我确切问题的方法。 这是代码: require ‘google/api_client’ client = Google::APIClient.new(:application_name => ‘something you like’, :application_version => ‘1’) client.authorization.access_token = ‘HERE_GOES_TOKEN’ ga = client.discovered_api(‘analytics’, ‘v3’) client.execute(:api_method => ga.management.accounts.list)

停止从谷歌的API获取刷新令牌

所以我有一个带有ruby on rails的web应用程序连接到google drive的API。 到目前为止,它曾用于接收刷新令牌,因为我使用的其中一个参数是离线的。 但最近它停止了它。 正在发送的url是: Redirected to https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=ID&options=%7B:access_type=%3E%22offline%22,%20:approval_prompt=%3E%22force%22%7D&redirect_uri=http://localhost:3000/oauth2callbackdrive&response_type=code&scope=https://www.googleapis.com/auth/drive%20https://www.googleapis.com/auth/userinfo.email 重定向到URI的代码包含: client = Google::APIClient.new client.authorization.client_id = GOOGLE_CLIENT_ID client.authorization.client_secret = GOOGLE_CLIENT_SECRET client.authorization.scope = SCOPES client.authorization.redirect_uri = GOOGLE_CLIENT_REDIRECT_URI auth_url = client.authorization.authorization_uri(:options => {:access_type => :offline, :approval_prompt => :force}.to_s) redirect_to auth_url.to_s 在回调函数上我有这个: client = Google::APIClient.new client.authorization.client_id = GOOGLE_CLIENT_ID client.authorization.client_secret = GOOGLE_CLIENT_SECRET client.authorization.scope = SCOPES client.authorization.redirect_uri = GOOGLE_CLIENT_REDIRECT_URI client.authorization.code […]

为什么Google API无论输入设置了+01偏移量?

我在此页面上使用Google的API Explorer作为其Calendar API。 我正在插入一个事件{ “end”: { “dateTime”: “2016-10-31T06:30:00Z” }, “start”: { “dateTime”: “2016-10-31T06:00:00Z” } }并尝试了以下日期时间格式: 2016-10-31T06:00:00Z 2016-10-31T06:00:00-00:00 2016-10-31T06:00:00+00:00 但无论输入格式如何,Google都会选择在设置日期时间时添加一小时。 响应总是: “start”: { “dateTime”: “2016-10-31T07:00:00+01:00” } 我目前在斯德哥尔摩,抵消时间+2小时。 我已经尝试设置单独的time_zone字段并省略单独的time_zone字段。 为什么会这样? 并且,有没有“正确的方法”或者我只是需要在设定时间时考虑这个额外的小时?

Google-api-client要求访问令牌

我的要求是在google.com上获取搜索查询的前20个链接。 我正在使用Google-api-client ! 对于ruby。 这是我正在使用的代码, require ‘google/api_client’ client = Google::APIClient.new response = client.execute( search.cse.list, ‘key’ => ”, ‘cx’ => ‘013036536707430787589%3A_pqjad5hr1a’, ‘alt’ => ‘json’, ‘q’ => ‘hello world’ ) 现在我面临三个问题, 我想使用默认的Google搜索,那么“cx”值应该是多少? 我使用的一个来自https://developers.google.com/custom-search/v1/using_rest#cx 我没有得到任何结果,而是收到以下警告“ArgumentError:缺少访问令牌”。 我通过定义“client.authorization.access_token =’123’”使用虚拟标记解决了这个问题。 但我不确定,如果这是一个正确的解决方案。 在我定义access_token之后,我仍然没有得到任何结果。 而是获取警告“无效的凭据”。 但如果我使用相同的URL(由api生成),在浏览器中我会得到结果。

在Ruby中更新Google Contact Picture时出现问题

我正在尝试编写一个ruby应用程序来更新Google联系人照片,但我无法让上传工作。 我不确定我是否误解了Google API,但这是我到目前为止所做的: Net::HTTP.start(URI.parse(image_element.attributes[‘href’]).host) do |http| response, body = http.put(URI.parse(image_element.attributes[‘href’]).path, data, {‘If-Match’ => ‘*’, ‘content-type’=>’image/*’}) end Google Data API说: 每个联系人都有一个照片链接元素。 它的forms如下: href =’https://www.google.com/m8/feeds/photos/media/liz%40gmail.com/c9012de’gd:etag =’“KTlcZWs1bCp7ImBBPV43VUV4LXEZCXERZAc。”’> 无论联系人是否有相关照片,都会显示该元素。 如果联系人确实有照片,则该元素包含gd:etag属性,用于指定照片的ETag。 如果联系人没有照片,则没有gd:etag属性,href属性提供用于向联系人添加照片的URL。 要根据上面显示的元素添加或更新照片,请将带有PUT命令的新照片发送到以下url: https : //www.google.com/m8/feeds/photos/media/liz%40gmail.com/c9012de 。 请记住设置正确的“image / *”Content-Type标头。 要删除照片,请将HTTP DELETE请求发送到同一URL。 更新或删除照片时,请在HTTP请求的If-Match标头中发送照片的ETag。 或者,使用If-Match:*更新或删除,无论您是否拥有最新版本的照片。 任何人都可以看到我错在哪里? 更新和答案:我已经设法在StackOverflow和配合的帮助下使用它。 基本上错误的是设置了不正确的MIME类型(见下文),但我没有正确地使用Google对PUT请求进行身份validation。 我试图写的是一个脚本,用Gravatar中的图像更新任何遗漏的Google联系人照片(如果可能)。 一旦我开始工作,它工作得很好:设法匹配大约2-3个联系人。 我写了一篇关于脚本的博客文章,以防任何人想要运行它: http : //ashleyangell.com/2011/06/ruby-script-to-import-google-contact-photos-from-gravatar/

在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 […]

为什么Google的自定义搜索API说我在使用Ruby客户端时缺少访问令牌?

我正在尝试通过Google API Ruby客户端使用Google的自定义搜索API 。 我已通过Google API控制台设置了我的API密钥,并且还创建了我的CSE。 根据文档,似乎只要我提供API密钥(我正在做),我就不需要OAuth2身份validation令牌来调用list方法。 但是,当我尝试执行下面的代码时,我收到以下错误: ArgumentError:缺少访问令牌。 我错过了什么? 这是我的代码: # create client client = Google::APIClient.new # Fetch discovery doc search = client.discovered_api(‘custom search’) # Call list method response = client.execute( search.cse.list, ‘key’ => ”, ‘cx’ => ”, ‘alt’ => ‘json’, ‘q’ => ‘hello world’ )

Rails中的plusAPmains.circles.addPeople的Google API生成403 Forbidden

使用: Google API Ruby Client class GooglePlus def self.follow_contact(contact, user = current_user) plus = GooglePlus.plus_domains GooglePlus. authorized(user). execute api_method: plus.circles.add_people, parameters: {circleId: “Following”, userId: contact} end private def self.plus_domains GooglePlus.client.discovered_api(‘plusDomains’) end def self.client require ‘google/api_client’ Google::APIClient.new( application_name: “My Application”, application_version: “1.0.0”, discovery_cache: ActiveSupport::Cache::Store ) end def self.authorized(user = current_user) client = GooglePlus.client client.authorization.client_id = Rails.application.secrets.google[:client_id] […]

使用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 […]