简体   繁体   English

阅读Google日历活动

[英]Read google calendar events

I want to read the events of a public google calendar without Oauth authentication. 我想在没有Oauth身份验证的情况下阅读公共Google日历的事件。 But i can't get a response: 但我无法得到回应:

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");
});

Any suggestions? 有什么建议么? Do i need to include an API-key for a public calendar? 我是否需要包括公共日历的API密钥?

I think the issue is your usage of the request library/function. 我认为问题是您对request库/函数的使用。 Per the docs The signature for that function is request(error, response, body) , but you only supply one argument. 根据文档 ,该函数的签名为request(error, response, body) ,但您仅提供一个参数。 Despite calling it response , it's actually the error object which is probably null . 尽管将其称为response ,但实际上是error对象,可能为null So, change it to the following and I bet it'll work: 因此,将其更改为以下内容,我敢打赌它将起作用:

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);
});

I think your API call to Google is fine as-is because the documentation says no authorization is needed. 我认为您对Google的API调用就可以了,因为文档说不需要授权。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM