Reputation: 1120
I would like load myVideo.avi on YouTube with my Qt5 programm. I successful authorisation through OAuth 2.0 and get access_token without errors.
But when I try to use API https://developers.google.com/youtube/v3/docs/videos/insert I get some erros!
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*)));
response-
"Host requires authentication"
"{
"error": {
"errors": [
{
"domain": "youtube.header",
"reason": "youtubeSignupRequired",
"message": "Unauthorized",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Unauthorized"
}
}
"
What I do wrong?
Upvotes: 4
Views: 6010
Reputation: 1706
Take a look at the solution in this question:
YouTube Data API v3 video upload 403 forbidden: YouTubeSignUpRequired
Catch the error and send the user to this YouTube site:
https://m.youtube.com/create_channel?chromeless=1&next=/channel_creation_done
Upvotes: 1
Reputation: 56104
youtubeSignupRequired
means that you're going through the OAuth 2 flow and authorizing access using a Google Account that doesn't have a YouTube channel associated with it yet. I'd recommend going through the flow again and confirming that you're authorizing access using the correct account.
As an aside, I'd recommend giving https://github.com/google/google-api-cpp-client a try. It's fairly new and may simplify your code vs. making the raw HTTP calls yourself.
Upvotes: 1