【问题标题】:Read google calendar events阅读谷歌日历活动
【发布时间】:2019-02-23 12:55:35
【问题描述】:

我想在没有 Oauth 身份验证的情况下阅读公共谷歌日历的事件。 但我无法得到回应:

const express = require("express");
const bodyParser = require("body-parser");
const request = require("request");
const app = express();

app.use(express.static("public"));
app.use(bodyParser.urlencoded({
  extended: true
}));


app.get("/", function(req, res) {
  res.sendFile(__dirname + "/index.html");
});




app.post("/", function(req,res){
  request("https://www.googleapis.com/calendar/v3/calendars/XXXXXXXXXXXX.calendar.google.com/events",function(response){

        var calendarSummary = response.summary;
        var calendarDescription =response.description;

        console.log("Response is:");
        console.log("Result is: "+calendarSummary+calendarDescription);
  });
});

app.listen(3000, function() {
  console.log("server is running on port 3000");
});

有什么建议吗?我是否需要为公共日历添加 API 密钥?

【问题讨论】:

  • 我也尝试在请求 URL 中添加“?key=[YOUR_API_KEY]”,但我没有从 Google 返回日历描述/摘要。我用我的谷歌开发者帐户 (console.developers.google.com) 中的密钥更改了 YOUR_API_KEY

标签: node.js express request google-calendar-api


【解决方案1】:

我认为问题在于您对 request 库/函数的使用。根据the docs,该函数的签名是request(error, response, body),但您只提供一个参数。尽管称它为response,它实际上是error 对象,可能是null。因此,将其更改为以下内容,我敢打赌它会起作用:

request("https://www.googleapis.com/calendar/v3/calendars/XXXXXXXXXXXX.calendar.google.com/events", function(error, response, body) {
  var calendarSummary = body.summary;
  var calendarDescription = body.description;
  console.log("Response is:");
  console.log("Result is: " + calendarSummary + calendarDescription);
});

我认为您对 Google 的 API 调用正常,因为 the documentation 表示不需要授权。

【讨论】:

  • 我尝试了上述解决方案,但没有从谷歌获得日历描述+摘要。终端中的响应是:未定义未定义。
猜你喜欢
  • 1970-01-01
  • 2015-06-20
  • 1970-01-01
  • 2011-11-11
  • 1970-01-01
  • 2013-07-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多