我正在尝试使用Qt C ++将事件插入到Google日历中。
在插入事件之前,我可以使用这些行清除主日历
const QUrl clearPrimaryUrl("https://www.googleapis.com/calendar/v3/calendars/primary/clear");
void GoogleWrapper::clearPrimaryCalendar()
{
QNetworkReply *reply = google.post(clearPrimaryUrl);
connect(reply, &QNetworkReply::finished, [=]()
{
reply->deleteLater();
if(reply->error() != QNetworkReply::NoError)
{
qCritical() << "Google error:" << reply->errorString();
return;
}
emit primaryCalendarCleared();
});
}
google
是QOAuth2AuthorizationCodeFlow对象。
现在插入事件,我使用以下行:
const QUrl insertEventUrl("https://www.googleapis.com/calendar/v3/calendars/primary/events");
void GoogleWrapper::insertEvent(const QByteArray &eventData)
{
qDebug() << eventData;
QNetworkReply *reply = google.post(insertEventUrl, eventData);
connect(reply, &QNetworkReply::finished, [=]()
{
reply->deleteLater();
if(reply->error() != QNetworkReply::NoError)
{
qCritical() << "Google error:" << reply->errorString();
return;
}
emit eventInserted();
});
}
但是我从qCritical收到的输出始终为Error transferring https://www.googleapis.com/calendar/v3/calendars/primary/events - server replied: Bad Request
。
我尝试将eventData
输出到文件并将其复制粘贴到Google's try this API,下面的json数据可以正常工作
{
"description": "some teacher name",
"end": {
"dateTime": "2018-12-19T11:15:00Z"
},
"location": "Room",
"start": {
"dateTime": "2018-12-19T09:30:00Z"
},
"summary": "Subject Name"
}
有人知道我做错了什么吗?
答案 0 :(得分:0)
通过“ thuga”评论,此问题得以解决。
我的代码缺少该行
google.setContentType(QAbstractOAuth2::ContentType::Json);