您好,我需要从 google 电子表格 API 访问电子表格。我启用了 Google Sheets API 并添加了 API key ,但这不起作用!!!
https://sheets.googleapis.com/v4/spreadsheets/[my_spreadsheet_id]/values/A1?key=[my_api_key]
结果是:
403 - 调用者没有权限
但是,如果我为这个电子表格提供公共(public)访问权限 ---> 它可以工作!!!
结果是:
200 - [正确请求的数据.....]
我的问题是:
如何从 API 访问私有(private)电子表格?
我需要使用诸如 file_get_contents() 之类的 php 函数从我的网站读取和写入订单数据
最佳答案
基本上,您需要获得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 时,所有应用程序都遵循以下步骤:
Before your application can access private data using a Google API, it must obtain an access token that grants access to that API.
最后,为了帮助您使用 PHP 实现,您还可以添加 Authentication and authorization到您的引用列表。希望有帮助!
关于php - 如何从 API 访问私有(private)电子表格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39747381/