我想用我的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"
}
}
"
我做错了什么?
youtubeSignupRequired
表示您正在通过OAuth 2流,并使用尚未关联YouTube频道的谷歌帐户授权访问。我建议您再次查看流程,并确认您正在使用正确的帐户授权访问。
顺便说一句,我建议https://github.com/google/google-api-cpp-client尝试一下。它是相当新的,与自己进行原始HTTP调用相比,可能会简化代码。
看看这个问题的解决方案:
YouTube数据API v3视频上传403禁止:YouTubeSignUpRequired
捕捉错误并将用户发送到此YouTube网站:
https://m.youtube.com/create_channel?chromeless=1&next=/channel_creation_done