我正在尝试使用node.js的google spreadsheet api创建新的google spreadsheet
我已经设法让谷歌OAuth 2.0正常工作,我正在为客户端获取访问令牌。
现在搜索Google API文档,有使用gData客户端库的示例,但没有给出指向node.js的指针
这是我创建一个新的google spreadhseet的发现
关于可恢复上传链接的信息不多。
我可以看到HTTP Post请求和响应,但我不知道如何在node.js中构造post请求
编辑--
发布于 2017-06-05 06:16:53
下面是如何使用Google Sheets API (当前为v4)的create
方法完成此操作。
此代码示例不使用任何第三方库,它使用googleapis
: Google API's official Node.js client
const google = require('googleapis');
const sheets = google.sheets('v4');
// authenticate, and store that authentication, in this example
// it is stored in a variable called `auth`. I am using JWT
// authentication, but you can use the any form of authentication
const auth = new google.auth.JWT(
key.client_email,
null,
key.private_key,
['https://www.googleapis.com/auth/spreadsheets'], // make sure that your auth scope includes `spreadsheets`, `drive` or `drive.file`
null
);
sheets.spreadsheets.create({
auth: auth,
resource: {
properties: {
title: 'Title of your new spreadsheet'
}
}
}, (err, response) => {
if (err) {
console.log(`The API returned an error: ${err}`);
return;
}
console.log('Created a new spreadsheet:')
console.log(response);
});
发布于 2012-09-28 09:28:20
如果您只想知道如何构造post请求,请查看此示例
http://nodejs.org/api/http.html#http_http_request_options_callback
发布于 2013-02-06 11:42:07
https://stackoverflow.com/questions/12622947
复制相似问题