首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ruby google_drive gem如何访问google drive

ruby google_drive gem如何访问google drive
EN

Stack Overflow用户
提问于 2016-01-14 14:15:34
回答 1查看 655关注 0票数 0

现在,随着google_drive gem的谷歌登录功能被弃用,我想知道如何访问电子表格?

我试着遵循下面的指南,但获取client_secret的链接断开了。我去谷歌开发人员那里给自己弄了一个包含client_ID的json文件,但现在我的简单代码输出了一个获取授权码的链接,但我不确定如何使用这个授权码。

代码语言:javascript
复制
http://www.rubydoc.info/gems/google_drive/1.0.5

有人能帮我用这个gem来访问我的电子表格吗?

我基本上是在尝试遵循文档中的示例。

代码语言:javascript
复制
require "google/api_client"
require "google_drive"

# Creates a session. This will prompt the credential via command line for the
# first time and save it to config.json file for later usages.
session = GoogleDrive.saved_session("config.json")

# First worksheet of
# https://docs.google.com/spreadsheet/ccc?key=pz7XtlQC-PYx-jrVMJErTcg
# Or https://docs.google.com/a/someone.com/spreadsheets/d/pz7XtlQC-PYx-jrVMJErTcg/edit?usp=drive_web
ws = session.spreadsheet_by_key("pz7XtlQC-PYx-jrVMJErTcg").worksheets[0]

# Gets content of A2 cell.
p ws[2, 1]  #==> "hoge"

# Changes content of cells.
# Changes are not sent to the server until you call ws.save().
ws[2, 1] = "foo"
ws[2, 2] = "bar"
ws.save

谢谢,

EN

回答 1

Stack Overflow用户

发布于 2016-01-25 23:44:50

授权码的事情只会出现一次(第一次尝试访问文档时)

当我尝试这样做时,我通过控制台进行了尝试,得到的响应如下:

Google::APIClient -使用选项{:application_name=>"google_drive Ruby library",:application_version=>"0.4.0"}初始化客户端

代码语言:javascript
复制
1. Open this page:
https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=***************************&redirect_uri=urn:ietf:wg:oauth:2.0:oob&response_type=code&scope=https://www.googleapis.com/auth/drive%20https://spreadsheets.google.com/feeds/

2. Enter the authorization code shown in the page: 

在转到给定的URL时,我得到了您提到的授权码。所以,我所做的就是按照上面的指示复制并粘贴代码( 2. Enter the authorization code shown in the page: )

就是这样。

在我的应用程序目录中创建了一个新文件,其中包含凭据、刷新令牌和所有内容。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34782828

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档