gpt4 book ai didi

node.js - 错误: Missing title - google calendar create or update

转载 作者:太空宇宙 更新时间:2023-11-04 02:45:52 24 4
gpt4 key购买 nike

我是issuing关于通过node js google apis package创建谷歌日历的问题。安装的版本是25.0.0

这个函数应该可以完成这项工作。 https://github.com/google/google-api-nodejs-client/blob/master/src/apis/calendar/v3.ts#L662

尝试官方API测试 https://developers.google.com/google-apps/calendar/v3/reference/calendars/insert#try-it正在工作,但我无法使用我的代码让它工作(也不能使用更新功能来更新日历)。这是我的代码:

var google = require('googleapis');
var googleAuth = require('google-auth-library');
var auth = new googleAuth();
var oauth2Client = new auth.OAuth2(clientId, clientSecret, redirectUrl);
oauth2Client.credentials = JSON.parse(user.calendarToken)
var calendar = google.calendar('v3');

function insertCalendar(){
calendar.calendars.insert({
resource : {
summary : req.body.newName // tried also JSON.stringify({resource:...}) and JSON.stringify({summary:---})
},
auth: auth
},function(err,newCal){
console.log("calendar should be created")
console.log(err) /* => output this { domain: 'global',
reason: 'required',
message: 'Missing title.' }*/
})
}

确切的错误转储是

{ Error: Missing title.
at new RequestError (/node_modules/google-auth-library/lib/transporters.js:34:42)
at Request._callback (/node_modules/google-auth-library/lib/transporters.js:96:27)
at Request.self.callback (/node_modules/request/request.js:188:22)
at emitTwo (events.js:126:13)
at Request.emit (events.js:214:7)
at Request.<anonymous> (/node_modules/request/request.js:1171:10)
at emitOne (events.js:116:13)
at Request.emit (events.js:211:7)
at IncomingMessage.<anonymous> (/node_modules/request/request.js:1091:12)
at Object.onceWrapper (events.js:313:30)
code: 400,
errors:
[ { domain: 'global',
reason: 'required',
message: 'Missing title.' } ] }

顺便提一下:

在调用之前(插入)我已经成功调用了这个

calendar.calendarList.list({ auth: auth },function(err,calendars){
console.log(calendars) // gives the user calendars list
insertCalendar()
})

Google 表示用于执行调用的代码 (js) 是

<script src="https://apis.google.com/js/api.js"></script>
<script>
function authenticate() {
return gapi.auth2.getAuthInstance()
.signIn({scope: "https://www.googleapis.com/auth/calendar"})
.then(function() { console.log("Sign-in successful"); },
function(err) { console.error("Error signing in", err); });
}
function loadClient() {
return gapi.client.load("https://content.googleapis.com/discovery/v1/apis/calendar/v3/rest")
.then(function() { console.log("GAPI client loaded for API"); },
function(err) { console.error("Error loading GAPI client for API", err); });
}
// Make sure the client is loaded and sign-in is complete before calling this method.
function execute() {
return gapi.client.calendar.calendars.insert({
"Su": {
"summary": "Room 1"
}
})
.then(function(response) {
// Handle the results here (response.result has the parsed body).
console.log("Response", response);
},
function(err) { console.error("Execute error", err); });
}
gapi.load("client:auth2", function() {
gapi.auth2.init({client_id: YOUR_CLIENT_ID});
});
</script>
<button onclick="authenticate().then(loadClient)">authorize and load</button>
<button onclick="execute()">execute</button>

因此,也尝试传递 {"Su": {"summary": "cal1"}} 而不是 {resource : {summary : "cal1"}} 但没有任何运气!

再次尝试 postman

调用 googleapis.com/calendar/v3/calendars (POST) 和 json 原始正文,如下所示:

{
summary : "Calname"
}

日历已创建。所以我猜这是谷歌图书馆的一个错误。我将尝试使用直接发布调用请求来解决此问题。

最佳答案

根据google node js库,您可以指定请求正文如下:

const res = await gmail.users.watch({
userId: 'me',
requestBody: {
topicName: `projects/el-gato/topics/gmail`
}
});

所以在你的情况下应该是:

function insertCalendar(title){
calendar.calendars.insert({
requestBody : {
summary : title
},
auth: auth
},function(err,newCal){
console.log("calendar should be created")
console.log(err)
})
}

检查here了解更多信息

关于node.js - 错误: Missing title - google calendar create or update,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48823797/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com