Доброго времени суток господа,надо сделать программу,загружающую видео на YouTube,вроде всё делаю по описанию youtube api,логинится вроде нормально(возвращает строку Auth),а вот при попытке загрузить уже видео сервер выдаёт bad request
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
but = new QPushButton("Upload");
layout()->addWidget(but);
connect(but,SIGNAL(clicked()),this,SLOT(staTimer()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::staTimer()
{
QNetworkRequest request;
request.setUrl(QUrl("https://www.google.com/youtube/accounts/ClientLogin"));
request.setHeader(QNetworkRequest::ContentTypeHeader,"application/x-www-form-urlencoded");
QByteArray reqString;
/////////Email=your email,passwd your pass
reqString = "Email=_______&Passwd=_____&service=youtube&source=test";
_networkMen = new QNetworkAccessManager();
_networkMen->post(request,reqString);
connect(_networkMen, SIGNAL(finished(QNetworkReply*)), this, SLOT(handleNetworkReply(QNetworkReply*)));
}
void MainWindow::handleNetworkReply(QNetworkReply *reply)
{
reply->ignoreSslErrors();
if (reply->error())
{
qDebug()<<reply->errorString();
}
else
{
QByteArray otv = reply->readAll();
QList<QByteArray> lst(otv.split('\n'));
lst.removeLast();
QByteArray auth(lst.at(0).split('=').at(1));
qDebug()<<otv;
qDebug()<<auth;
QFile f("C:\\test.avi"); //video file
f.open(QIODevice::ReadOnly);
QByteArray fileBinaryData(f.readAll());
f.close();
QNetworkRequest request;
// forming request
request.setUrl(QUrl("http://uploads.gdata.youtube.com/feeds/api/users/default/uploads"));
request.setRawHeader("Authorization","GoogleLogin auth="+auth);
request.setRawHeader("GData-Version","2");
request.setRawHeader("X-GData-Key","key=AI39si53w0jmcZxorzxniPVD_rGBRZJhShx6Bh7uKy-JmAn--BAKzINwR3lNzvOtqnClFlCRiXsk-j8UMaE-EAO9U-7EsDJRxg");
request.setRawHeader("Slug","test.avi");
request.setRawHeader("Content-Type","multipart/related; boundary=\"f93dcbA3\"");
request.setRawHeader("Content-Length",QString::number(fileBinaryData.length()).toStdString().c_str());
request.setRawHeader("Connection","close");
QByteArray reqString;
reqString.append("--f93dcbA3\r\n");
reqString.append("Content-Type: application/atom+xml; charset=UTF-8\r\n");
reqString.append("\r\n");
reqString.append("<?xml version=\"1.0\"?>\r\n");
reqString.append("<entry xmlns=\"http://www.w3.org/2005/Atom\"\r\n");
reqString.append("xmlns:media=\"http://search.yahoo.com/mrss/\"\r\n");
reqString.append("xmlns:yt=\"http://gdata.youtube.com/schemas/2007\">\r\n");
reqString.append("<media:group>\r\n");
reqString.append("<media:title type=\"plain\">Test test</media:title>\r\n");
reqString.append("<media:description type=\"plain\">\r\n");
reqString.append("Batafa\r\n");
reqString.append("</media:description>\r\n");
reqString.append("<media:category\r\n");
reqString.append("scheme=\"http://gdata.youtube.com/schemas/2007/categories.cat\">People\r\n");
reqString.append("</media:category>\r\n");
reqString.append("<media:keywords>ara,arara</media:keywords>\r\n");
reqString.append("</media:group>\r\n");
reqString.append("</entry>\r\n");
reqString.append("--f93dcbA3\r\n");
reqString.append("Content-Type: video/*\r\n");
reqString.append("Content-Transfer-Encoding: binary\r\n");
reqString.append("\r\n");
reqString.append(fileBinaryData);
reqString.append("\r\n");
reqString.append("--f93dcbA3");
netmen2 = new QNetworkAccessManager();
QNetworkReply *rep=netmen2->post(request,reqString);
rep->ignoreSslErrors();
connect(netmen2, SIGNAL(finished(QNetworkReply*)), this, SLOT(handleUploadReply(QNetworkReply*)));
}
}
void MainWindow::handleUploadReply(QNetworkReply *reply)
{
reply->ignoreSslErrors();
if(reply->error())
{
qDebug()<<reply->errorString();
} else
{
qDebug()<<reply->readAll();
}
}
Что я делаю неправильно?заранее спасибо.