2013-08-21 285 views
4

我想用我的Qt5程序在YouTube上加載myVideo.avi。我通過OAuth 2.0成功授權並獲得access_token而沒有錯誤。YouTube API v3 - 上傳視頻

但是,當我嘗試使用API​​ https://developers.google.com/youtube/v3/docs/videos/insert 我得到了一些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*))); 

應答爲

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

我做什麼了?

+0

我怎麼沒看到你瀏覽OAuth2或將您的令牌應用到客戶端。 –

回答

1

youtubeSignupRequired意味着您正在瀏覽OAuth 2流,並使用尚未與其關聯的YouTube頻道的Google帳戶授權訪問。我建議再次通過流程,並確認您使用正確的帳戶授權訪問。

另外,我建議試一試https://github.com/google/google-api-cpp-client。這是相當新的,可能會簡化您的代碼,而不是自己製作原始HTTP調用。

+0

謝謝,它的工作! –

相關問題