在Google Spreadsheet API中使用OAuth 2.0授权请求 [英] Authorizing requests with OAuth 2.0 in Google Spreadsheet API

查看:164
本文介绍了在Google Spreadsheet API中使用OAuth 2.0授权请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试创建一个PHP网页,需要从我的域中的Google电子表格中读取一些数据(我正在使用Google Apps免费版)。

要阅读的电子表格是非公开的电子表格,但我的网域中的某些人可以看到。由于它是非公开的,我知道会有一些认证和授权的东西,即使我使用API​​来读取它。



我找到了这个页面,但有一些东西我不明白:
http://code.google.com/intl/zh-TW/apis/spreadsheets/data/3.0/developers_guide.html#Auth



它说我们应该使用OAuth 2.0协议,这没关系。但它也表示在授权过程中,Google向用户显示一个OAuth对话框,要求他们授权您的应用程序请求他们的一些数据。



我的网页会显示一些从电子表格中读取的数据。因此,每当有人前往我的网页时,它会向电子表格所有者显示一个对话框,要求获得许可?这是什么意思?



任何建议都将非常受欢迎。 解决方案

您实际上想要完成的是您的服务器与Google之间的服务器到服务器身份验证。



这样,当访问者进入您的页面时,您可以从您自己的电子表格中获取数据,而不需要任何第三方参与。



我不可能在 Google服务帐户 here

另外,
是另一个解决方案(可能会有一些挫折)是使用oauth 2.0协议与您的Google开发者帐户(从Google Console API检索)。


    <李>如果你还没有,创建一个Goog le开发人员帐户(Google Console API)
  1. 使用离线授予为您的应用程序生成访问/刷新令牌 - 这意味着您可以使用开发者帐户向您的电子表格帐户发出API请求,即使在您没有使用电子表格帐户登录。

  2. 保存您生成的刷新令牌并使用它重复生成访问令牌(访问令牌持续1小时)。
  3. >

刷新令牌不会过期,但如果情况确实如此,您可以随时再次生成它,并将其替换为新的,并持续生成访问令牌。



最主要的原因是您的刷新令牌失效,您必须手动替换它,因为它需要您可以重新授予您的开发者帐户访问权限,以访问您的电子表格帐户。



我希望这会有所帮助。



梅尼


I am trying to create a PHP web page that requires reading some data from a google spreadsheet in my domain (I am using Google Apps Free Edition).

The spreadsheet to be read is a non-public one but is visible to some people in my domain. Since it's non-public, I know there will be some authentication and authorization stuff even I am using the API to read it.

I found this page but there is something that I don't understand: http://code.google.com/intl/zh-TW/apis/spreadsheets/data/3.0/developers_guide.html#Auth

It says we should use OAuth 2.0 protocol, this is ok. But it also says during the authorizing process, "Google displays an OAuth dialog to the user, asking them to authorize your application to request some of their data.".

My webpage will display some data read from the spreadsheet. So whenever somebody goes to my webpage, it will display a dialog to the spreadsheet owner asking for permission? Is this what it means?

Any advice will be very welcome.

解决方案

What you're actually trying to accomplish is Server to Server authentication between your server and Google.

This way, when a visitor enters your page/s you'll grab data from your own spreadsheet, without any 3rd party involvement.

I'ts possible you'll find what you're looking for in Google Service Account, and here

Also, another solution (which is much easier to accomplish, but might have some set backs) is to use the oauth 2.0 protocol with your Google dev account (retrieved from Google Console API).

  1. If you haven't already, create a Google Dev account (Google Console API)
  2. Generate a access/refresh token for your application with "offline" grant - meaning you can make API requests with your dev account to your spreadsheet account even when you're not logged in with your spreadsheet account.
  3. Save the refresh token you generated and use it to generate access token over and over again (access tokens last 1 hour).

Refresh token are not supposed to expire, but in case it would, you can always generate it again and replace the one you had with a new one, and keep generating access tokens with it.

The major set back is in case your refresh token gets invalidated, you'll have to manually replace it, as it will require you to re-grant access to your dev account to access your spreadsheet account.

I hope this helps a bit.

Meny

这篇关于在Google Spreadsheet API中使用OAuth 2.0授权请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆