YouTube API v3 - upload video

I want to upload myVideo.avi to YouTube using my Qt5 program. I successfully log in through OAuth 2.0 and get access_token without errors.

But when I try to use the API https://developers.google.com/youtube/v3/docs/videos/insert I get some errors!

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*))); 

the answer is

 "Host requires authentication" "{ "error": { "errors": [ { "domain": "youtube.header", "reason": "youtubeSignupRequired", "message": "Unauthorized", "locationType": "header", "location": "Authorization" } ], "code": 401, "message": "Unauthorized" } } " 

What am I doing wrong?

+4
source share
2 answers

youtubeSignupRequired means you go through the OAuth 2 stream and authorize access with a Google account that does not yet have a YouTube channel associated with it. I would recommend going through the stream again and confirming that you are allowing access using the correct account.

As an aside, I would recommend trying https://github.com/google/google-api-cpp-client . This is fairly new and can simplify your code as well as make your own HTTP calls.

+1
source

Take a look at the solution in this question:

YouTube Data API v3 for 403 video upload prohibited: YouTubeSignUpRequired

Understand the error and send the user to this YouTube site:

https://m.youtube.com/create_channel?chromeless=1&next=/channel_creation_done

+1
source

Source: https://habr.com/ru/post/1498148/


All Articles