连接到Google电子表格
我有一个使用Perl创建的Web应用程序,并且在电子表格文档上有一个表格,我想将我的应用程序连接到电子表格,我尝试了文档,但我无法获得令牌 这是我所做的:
sub authenticate {
my $oauth2 = Net::Google::DataAPI::Auth::OAuth2->new(
client_id => 'my client id',
client_secret => 'my secret code',
scope => ['http://spreadsheets.google.com/feeds/'],
);
my $url = $oauth2->authorize_url(access_type => 'offline', approval_prompt => 'force');
use Data::Dumper;
Core::Global::Logger::debug(Dumper($url));
#you will need to put code here and receive token
print "OAuth URL, get code: \n$url\n";
use Term::Prompt;
my $code = prompt('x', 'my code', '', '');
my $token = $oauth2->get_access_token($code) or die;
#save token for future use
my $session = $token->session_freeze;
store( $session, 'google_spreadsheet.session' );
}
i have a web app created using perl, and i have a table on a spreadsheet document, i want to connect my app to the spreadsheet, i tried the documentation but i can't get the token
here is what i did:
sub authenticate {
my $oauth2 = Net::Google::DataAPI::Auth::OAuth2->new(
client_id => 'my client id',
client_secret => 'my secret code',
scope => ['http://spreadsheets.google.com/feeds/'],
);
my $url = $oauth2->authorize_url(access_type => 'offline', approval_prompt => 'force');
use Data::Dumper;
Core::Global::Logger::debug(Dumper($url));
#you will need to put code here and receive token
print "OAuth URL, get code: \n$url\n";
use Term::Prompt;
my $code = prompt('x', 'my code', '', '');
my $token = $oauth2->get_access_token($code) or die;
#save token for future use
my $session = $token->session_freeze;
store( $session, 'google_spreadsheet.session' );
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我无法制作 net :: Google :: Google :: google :: vendereets :: v4 < /a>使用服务帐户并使用 net :: google :: dataapi :: dataapi :: auth :: auth :: auth :: oauth2 获取访问令牌。但是您应该能够从 Google :: Cloud :: Auth :: Serviceaccount 而不是使用该令牌授权请求到Google Drive REST API。以下对我有用:
编辑:
要获得具有给定ID的给定表的单元格值,您可以使用以下URL:
https://sheets.googleapis.com /v4/电子表格/%s/values/%s
,其中第一个%s
被表的ID代替,第二个%s
代表要提取的细胞范围。这是一个示例:I was not able to make Net::Google::Spreadsheets::V4 work with a service account and using Net::Google::DataAPI::Auth::OAuth2 to get the access token. But you should be able to get the access token from WWW::Google::Cloud::Auth::ServiceAccount instead, and then use that token to authorize requests to the google drive rest api. The following worked for me:
Edit:
To get the value of a cell for a given sheet with a given id, you can use the following url:
https://sheets.googleapis.com/v4/spreadsheets/%s/values/%s
where the first%s
is replaced by the id of the sheet and the second%s
represents the cell range to extract. Here is an example: