从 Google 日历 API 收到错误请求
Get bad request from Google calendar API
我正在尝试使用 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"
}
有人知道我做错了什么吗?
感谢@thuga 的评论,问题已解决。
我的代码缺少行
google.setContentType(QAbstractOAuth2::ContentType::Json);
我正在尝试使用 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"
}
有人知道我做错了什么吗?
感谢@thuga 的评论,问题已解决。
我的代码缺少行
google.setContentType(QAbstractOAuth2::ContentType::Json);