Tag: 谷歌驱动 SDK

Google Drive API监视400错误Ruby on Rails

我正在使用OAuth2 gem(ruby on rails)实现google驱动器api。 我没有使用客户端库,因为我也在集成其他API,所以我试图将所有这些调用尽可能地模块化。 我遇到了这个请求的问题: POST https://www.googleapis.com/drive/v2/changes/watch 。 我一直收到这个错误: {“errors”=>[{“domain”=>”global”, “reason”=>”required”, “message”=>”entity.resource”}], “code”=>400, “message”=>”entity.resource”}: { “error”: { “errors”: [ { “domain”: “global”, “reason”: “required”, “message”: “entity.resource” } ], “code”: 400, “message”: “entity.resource” } } 这不是很有用。 它可能不是谷歌。 它可能是OAuth2,但我不这么认为,因为调试器在建立连接后会得到响应。 好吧,在这一点上,我什么都不知道,所以任何帮助都表示赞赏。 有这个GUY谁有与我完全相同的错误代码,以及相同的结论。 无论如何,相关的代码部分: 首先,我传递给OAuth2 :: AccessToken的post方法的参数(我需要超过10个rep来发布另一个链接,但这里是dochttp://rdoc.info/github/intridea/oauth2/ebe4be038ec14b349682/OAuth2/AccessToken#post -instance_method)(您可以单击请求方法以查看如何处理参数) base_url = request.protocol + request.host_with_port channel_id = (0…50).map { (‘a’..’z’).to_a[rand(26)] […]

停止从谷歌的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 […]

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

让Google文件选择器与drive.file范围一起使用

我正在尝试使用Google文件选择器来选择文档,然后更新其权限。 我不需要访问所有选定的驱动器文件。 但是,在使用https://www.googleapis.com/auth/drive.file范围时,我在尝试更改文档权限时收到404错误。 如果我使用https://www.googleapis.com/auth/drive范围,我不会收到此错误,但这会给我提供比我需要的更多访问权限。 有没有办法让文件选择器使用更有限的https://www.googleapis.com/auth/drive.file范围? 这是我的文件选择器代码: // Use the Google Loader script to load the google.picker script. //google.setOnLoadCallback(createPicker); google.load(‘picker’, ‘1’); // Create and render a Picker object function createPicker() { var view = new google.picker.DocsView(google.picker.ViewId.DOCS); view.setMode(google.picker.DocsViewMode.LIST); //view.setMimeTypes(“image/png,image/jpeg,image/jpg”); var picker = new google.picker.PickerBuilder() //.enableFeature(google.picker.Feature.NAV_HIDDEN) //.enableFeature(google.picker.Feature.MULTISELECT_ENABLED) .setAppId(“”) .setOAuthToken(“”) //Optional: The auth token used in the current Drive […]

使用API​​将一张幻灯片从Google幻灯片复制到新的演示文稿中

我希望使用Google Drive API创建新的Google幻灯片,但是从另一个以前的演示文稿复制了一张幻灯片。 我的问题是,是否可以构建一个新的Google幻灯片并将幻灯片(单个)插入新幻灯片中。 或者是否可以从Google演示文稿中删除幻灯片?

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

是否有可能’卸载’(’un-require’)Ruby库?

我正在寻找加载一些库,让他们做一些工作,然后执行相反的require以避免以后的兼容性错误。 我不想转储到文件并重新启动shell,因为创建的对象(例如data )可以由我的其他库很好地处理,只是不存在我想要卸载的早期文件。 有人有任何建议或知道这是否可行? 2006年的一次谈话并没有得出多少结论,除了“看起来Webrick设法以某种方式做到这一点”。 有问题的库是Google_drive和Nokogiri (电子表格处理库Roo依赖于Google_drive进行在线电子表格读/写,如该链接所述)。

Ruby google_drive gem oAuth2节省

因此,在更新之前有一种简单的方法来登录谷歌驱动器并操纵您的谷歌文档 – 使用ruby。 在您使用此function登录Google云端硬盘之前。 require ‘google_drive’ $session = GoogleDrive.login(“email@gmail.com”, “password”) 但现在你收到警告信息: WARNING: GoogleDrive.login is deprecated and will be removed in the next version. Use GoogleDrive.login_with_oauth instead. 所以我去了git hub页面看看google是如何让我们使用高级语言的服务,并发现他们希望我们使用oAuth2。 像这样。 require ‘google/api_client’ require ‘google_drive’ client = Google::APIClient.new( :application_name => ‘Example Ruby application’, :application_version => ‘1.0.0’ ) auth = client.authorization auth.client_id = “YOUR CLIENT ID” auth.client_secret = […]