YouTube API v3 - upload video



  • 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":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?


  • Moderators

    don't you use the same QNAM instance you use for authorization?



  • [quote author="raven-worx" date="1377076229"]don't you use the same QNAM instance you use for authorization?[/quote]

    No, I use two different instance QNAM. It's important to use the same?


  • Moderators

    maybe...it was just a guess of mine regarding the error message.
    It may be that the authorization response sets some cookies which are missing for the following requests.



  • I try, It's not work =(
    [quote author="raven-worx" date="1377078657"]maybe...it was just a guess of mine regarding the error message.
    It may be that the authorization response sets some cookies which are missing for the following requests.[/quote]


  • Moderators

    same error?
    Does the RAW HTTP request look as it should?

    show some code please.



  • How I can get it?

    @for(QByteArray arr : request.rawHeaderList()){
    qDebug() << arr;
    }@

    not work
    [quote author="raven-worx" date="1377079515"]same error?
    Does the RAW HTTP request look as it should?

    show some code please.
    [/quote]



  • try connecting
    @QNetworkAccessManager::authenticationRequired(QNetworkReply * reply, QAuthenticator * authenticator)@
    to a custom slot to test if you need authentication.


  • Moderators

    [quote author="yatongen" date="1377080073"]How I can get it?

    @for(QByteArray arr : request.rawHeaderList()){
    qDebug() << arr;
    }@

    not work
    [/quote]
    not only the raw headers. But use an application like "fiddler ":http://fiddler2.com to sniff out the HTTP-traffic.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.