我想用我的 Qt5 程序在 YouTube 上加载 myVideo.avi。我通过 OAuth 2.0 成功授权并获得 access_token 没有错误。
但是当我尝试使用 API https://developers.google.com/youtube/v3/docs/videos/insert 我得到了一些错误!
QString googleApiUrl = "https://www.googleapis.com/upload/youtube/v3/videos?access_token="+authorisation->getAccessToken()+"&part=snippet";
QNetworkRequest request;
request.setUrl(QUrl(googleApiUrl));
QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::MixedType);
QHttpPart videoPart;
videoPart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("video/*"));
videoPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("Slug"));
m_video = new QFile(m_filePath);
if (m_video->open(QIODevice::ReadOnly)) {
videoPart.setBodyDevice(m_video);
}
multiPart->append(videoPart);
m_networkManager = new QNetworkAccessManager();
m_networkManager->post(request,multiPart);
connect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(handleNetworkReply(QNetworkReply*)));
回复-
"Host requires authentication"
"{
"error": {
"errors": [
{
"domain": "youtube.header",
"reason": "youtubeSignupRequired",
"message": "Unauthorized",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Unauthorized"
}
}
"
我做错了什么?