If you want to use the latest API (v4), you'll need to do the following:
- 生成Electron 表格API密钥(参见下面的说明).
- Make your sheet publicly accessible.
Use a request of the form:
https://sheets.googleapis.com/v4/spreadsheets/SPREADSHEET_ID/values/RANGE?key=API_KEY
然后,您将得到一个干净的JSON响应:
{
"range": "Sheet1!A1:D5",
"majorDimension": "ROWS",
"values": [
["Item", "Cost", "Stocked", "Ship Date"],
["Wheel", "$20.50", "4", "3/1/2016"],
["Door", "$15", "2", "3/15/2016"],
["Engine", "$100", "1", "30/20/2016"],
["Totals", "$135.5", "7", "3/20/2016"]
],
}
请注意,如果要指定页面的全部内容,则标识符(如Sheet1
)是perfectly valid.
See Basic Reading for more information.
As of v4 API, all requests must be accompanied by an identifier (e.g. API key):
Requests to the Google Sheets API for public data must be accompanied by an identifier, which can be an API key or an access token.
Follow the steps in the linked document to create an API key on the credentials page.
确保:
- Create a new app on Google Cloud Platform.
- 创建一个新的API密钥.
- Add the Google Sheets API. (API Manager > Dashboard > Enable API)
Note that you can still access public data without forcing the user to log in:
在新版API v4中,没有明确的可见性声明.API调用是使用Electron 表格ID进行的.如果应用程序没有访问指定Electron 表格的权限,则返回错误.否则通话将继续.
Note that you do not need to publish the sheet to the web. All you need to do is make sure anyone with the link can access the sheet.
(也就是说,当你在Google Sheets API上点击Create credentials时, Select 其他非UI用户数据,它会显示"用户数据不能从没有UI的平台上访问,因为它需要用户交互才能登录."你可以放心地忽略这个信息.API密钥是您真正需要的,因为这是公共数据.)
Common error messages:
The request is missing a valid API key.
You didn't include the key=
param in your call.
API key not valid. Please pass a valid API key.
Google developers console
You supplied an incorrect API key. Make sure that you typed in your key correctly. If you don't have a key yet, go to the Google developers console and create one.
API Key not found. Please pass a valid API key.
Google developer console API key
您的API密钥可能是正确的,但您很可能没有添加Google Sheets权限.转到Google开发者控制台API密钥页面,添加表单权限.
呼叫方没有权限
Your sheet isn't set to be publicly accessible.