4

我想用我的 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"
}
}
"

我做错了什么?

4

2 回答 2

1

youtubeSignupRequired表示您正在通过 OAuth 2 流程并使用尚未与 YouTube 频道关联的 Google 帐户授权访问。我建议您再次完成流程并确认您正在使用正确的帐户授权访问。

顺便说一句,我建议尝试一下https://github.com/google/google-api-cpp-client。它是相当新的,并且可以简化您的代码而不是自己进行原始 HTTP 调用。

于 2013-08-21T21:32:04.747 回答
1

看看这个问题的解决方案:

YouTube Data API v3 视频上传 403 被禁止:YouTubeSignUpRequired

捕获错误并将用户发送到此 YouTube 站点:

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

于 2014-07-08T15:38:25.517 回答