错误:缺少标题 - 谷歌日历创建或更新

时间:2018-02-16 09:37:32

标签: node.js google-api google-calendar-api google-api-nodejs-client google-apis-explorer

issuing关于通过node js google apis package创建Google日历的问题。已安装的版本为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"}}而没有任何运气!

另一次尝试 邮差

按如下方式调用googleapis.com/calendar/v3/calendars(POST)和json原始主体:

{
    summary : "Calname"
}

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

2 个答案:

答案 0 :(得分:0)

根据Google节点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以获得更多信息

答案 1 :(得分:-1)

使用 POSTMAN

并按如下方式调用googleapis.com/calendar/v3/calendars(POST)和json原始主体:

{
    summary : "Calname"
}

并且库提供的令牌作为承载令牌,创建日历。

所以我猜这个问题是谷歌库的一个漏洞。我将尝试使用直接发布呼叫请求来解决此问题。