如何从 API 访问私人电子表格?
How to get access to a private spreadsheet from the API?
您好,我需要从 google 电子表格 API 访问电子表格。我启用了 Google Sheets API 并添加了 API 键,但这不起作用!!!
https://sheets.googleapis.com/v4/spreadsheets/[my_spreadsheet_id]/values/A1?key=[my_api_key]
结果是:
403 - 调用者没有权限
但是,如果我为该电子表格提供 public 访问权限 ---> 它会起作用!!!
结果是:
200 - [正确请求的数据.....]
我的问题是:
如何从 API?
访问私人电子表格
我需要使用 php 的函数(例如 file_get_contents()
从我的网站读取和写入订单数据
基本上,您需要获得documentation中提到的授权。
Whenever your application requests private user data, it must send an OAuth 2.0 token along with the request. Your application first sends a client ID and, possibly, a client secret to obtain a token. You can generate OAuth 2.0 credentials for web applications, service accounts, or installed applications.
来自 OAuth 2.0 documentation 的更多信息,当使用 OAuth 2.0 访问 Google API 时,所有应用程序都遵循以下步骤:
- 从 Google API 控制台获取 OAuth 2.0 凭据。
- 从 Google 授权服务器获取访问令牌。
Before your application can access private data using a Google API, it must obtain an access token that grants access to that API.
- 将访问令牌发送到 API。
- 如有必要,刷新访问令牌。
最后,为了帮助您使用 PHP 进行实施,您还可以将 Authentication and authorization 添加到您的参考列表中。希望对您有所帮助!
您好,我需要从 google 电子表格 API 访问电子表格。我启用了 Google Sheets API 并添加了 API 键,但这不起作用!!! https://sheets.googleapis.com/v4/spreadsheets/[my_spreadsheet_id]/values/A1?key=[my_api_key]
结果是: 403 - 调用者没有权限
但是,如果我为该电子表格提供 public 访问权限 ---> 它会起作用!!!
结果是: 200 - [正确请求的数据.....]
我的问题是: 如何从 API?
访问私人电子表格我需要使用 php 的函数(例如 file_get_contents()
从我的网站读取和写入订单数据基本上,您需要获得documentation中提到的授权。
Whenever your application requests private user data, it must send an OAuth 2.0 token along with the request. Your application first sends a client ID and, possibly, a client secret to obtain a token. You can generate OAuth 2.0 credentials for web applications, service accounts, or installed applications.
来自 OAuth 2.0 documentation 的更多信息,当使用 OAuth 2.0 访问 Google API 时,所有应用程序都遵循以下步骤:
- 从 Google API 控制台获取 OAuth 2.0 凭据。
- 从 Google 授权服务器获取访问令牌。
Before your application can access private data using a Google API, it must obtain an access token that grants access to that API.
- 将访问令牌发送到 API。
- 如有必要,刷新访问令牌。
最后,为了帮助您使用 PHP 进行实施,您还可以将 Authentication and authorization 添加到您的参考列表中。希望对您有所帮助!