Results 1 to 16 of 16

Thread: youtube upload

  1. #1
    Join Date
    Oct 2010
    Posts
    11
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default youtube upload

    Hi guys.
    I make a yotube appload application,using youtube api clientlogin.
    First request performed good and server returned me auth key,but on second request(when i try to upload video),server return me bad request.

    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow)
    4. {
    5. ui->setupUi(this);
    6. but = new QPushButton("Upload");
    7. layout()->addWidget(but);
    8. connect(but,SIGNAL(clicked()),this,SLOT(staTimer()));
    9. }
    10.  
    11. MainWindow::~MainWindow()
    12. {
    13. delete ui;
    14. }
    15.  
    16.  
    17. void MainWindow::staTimer()
    18. {
    19. QNetworkRequest request;
    20. request.setUrl(QUrl("https://www.google.com/youtube/accounts/ClientLogin"));
    21. request.setHeader(QNetworkRequest::ContentTypeHeader,"application/x-www-form-urlencoded");
    22. QByteArray reqString;
    23. /////////Email=your email,passwd=your pass
    24. reqString = "Email=_______&Passwd=_____&service=youtube&source=test";
    25. _networkMen = new QNetworkAccessManager();
    26. _networkMen->post(request,reqString);
    27. connect(_networkMen, SIGNAL(finished(QNetworkReply*)), this, SLOT(handleNetworkReply(QNetworkReply*)));
    28. }
    29.  
    30. void MainWindow::handleNetworkReply(QNetworkReply *reply)
    31. {
    32. reply->ignoreSslErrors();
    33. if (reply->error())
    34. {
    35. qDebug()<<reply->errorString();
    36. }
    37. else
    38. {
    39. QByteArray otv = reply->readAll();
    40. QList<QByteArray> lst(otv.split('\n'));
    41. lst.removeLast();
    42. QByteArray auth(lst.at(0).split('=').at(1));
    43. qDebug()<<otv;
    44. qDebug()<<auth;
    45. QFile f("C:\\test.avi"); //video file
    46. f.open(QIODevice::ReadOnly);
    47. QByteArray fileBinaryData(f.readAll());
    48. f.close();
    49. QNetworkRequest request;
    50. // forming request
    51. request.setUrl(QUrl("http://uploads.gdata.youtube.com/feeds/api/users/default/uploads"));
    52. request.setRawHeader("Authorization","GoogleLogin auth="+auth);
    53. request.setRawHeader("GData-Version","2");
    54. request.setRawHeader("X-GData-Key","key=AI39si53w0jmcZxorzxniPVD_rGBRZJhShx6Bh7uKy-JmAn--BAKzINwR3lNzvOtqnClFlCRiXsk-j8UMaE-EAO9U-7EsDJRxg");
    55. request.setRawHeader("Slug","test.avi");
    56. request.setRawHeader("Content-Type","multipart/related; boundary=\"f93dcbA3\"");
    57. request.setRawHeader("Content-Length",QString::number(fileBinaryData.length()).toStdString().c_str());
    58. request.setRawHeader("Connection","close");
    59. QByteArray reqString;
    60. reqString.append("--f93dcbA3\r\n");
    61. reqString.append("Content-Type: application/atom+xml; charset=UTF-8\r\n");
    62. reqString.append("\r\n");
    63. reqString.append("<?xml version=\"1.0\"?>\r\n");
    64. reqString.append("<entry xmlns=\"http://www.w3.org/2005/Atom\"\r\n");
    65. reqString.append("xmlns:media=\"http://search.yahoo.com/mrss/\"\r\n");
    66. reqString.append("xmlns:yt=\"http://gdata.youtube.com/schemas/2007\">\r\n");
    67. reqString.append("<media:group>\r\n");
    68. reqString.append("<media:title type=\"plain\">Test test</media:title>\r\n");
    69. reqString.append("<media:description type=\"plain\">\r\n");
    70. reqString.append("Batafa\r\n");
    71. reqString.append("</media:description>\r\n");
    72. reqString.append("<media:category\r\n");
    73. reqString.append("scheme=\"http://gdata.youtube.com/schemas/2007/categories.cat\">People\r\n");
    74. reqString.append("</media:category>\r\n");
    75. reqString.append("<media:keywords>ara,arara</media:keywords>\r\n");
    76. reqString.append("</media:group>\r\n");
    77. reqString.append("</entry>\r\n");
    78. reqString.append("--f93dcbA3\r\n");
    79. reqString.append("Content-Type: video/*\r\n");
    80. reqString.append("Content-Transfer-Encoding: binary\r\n");
    81. reqString.append("\r\n");
    82. reqString.append(fileBinaryData);
    83. reqString.append("\r\n");
    84. reqString.append("--f93dcbA3");
    85. netmen2 = new QNetworkAccessManager();
    86. netmen2->post(request,reqString);
    87. connect(netmen2, SIGNAL(finished(QNetworkReply*)), this, SLOT(handleUploadReply(QNetworkReply*)));
    88. }
    89. }
    90.  
    91. void MainWindow::handleUploadReply(QNetworkReply *reply)
    92. {
    93. reply->ignoreSslErrors();
    94. if(reply->error())
    95. {
    96. qDebug()<<reply->errorString();
    97. } else
    98. {
    99. qDebug()<<reply->readAll();
    100. }
    101. }
    To copy to clipboard, switch view to plain text mode 

    what i do wrong?thanks
    Last edited by wysota; 11th December 2010 at 16:09. Reason: changed [qtclass] to [code]

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: youtube upload

    Why do you create request by simple string concatenation rather than use proper MIME library?

    Is your unique developer key correct ? and did you encode it into the data correctly ? [I wouldn't include this in your posts BTW even though it is likely to be stored in your application and transmitted in plain text]

    Try using something like Wireshark to determine exactly what you are sending, and compare it with a program known to work.

    Or you could just use the Youtube client API library, which handles all this for you.

  3. #3
    Join Date
    Oct 2010
    Posts
    11
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: youtube upload

    squidge,thanks for reply,i use wireshark and determinate my post request and post request from youtube api sample,it's same.
    how can i use the proper MIME library?i don't know about it in Qt,sorry
    developer key correct,i copied it from http://code.google.com/apis/youtube/dashboard for my app(don't worry,it's test app and key not secret )
    how encode data correct?i try to convert bynary data to base64 (fileBinaryData.toBase64()),but it's not given result.
    youtube give libraries for java,c# ,not for c++ unfortunately

  4. #4
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: youtube upload

    So your sending exactly the same data as the api sample, but the sample works and yours does not? That is most odd, but at least it proves that the encoding and mime headers are already correct, so there's really no point changing something that works.

  5. #5
    Join Date
    Oct 2010
    Posts
    11
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: youtube upload

    yes,header(i sure) and body(i think) of request is same as api sample,but i thinks it's must be because i encode file binary data wrong?i try to delete video with my auth data and video is deleted,i think headers is true,may body of post request is wrong?i can't try the sample to work(request in sample and in my programm is identical),may it dapend on country where are i from?some says,that upload api work worst in China and another countries, i'm from Russia and i can upload video with youtube web interface without problem,what application you can advise for me to try upload video to youtube besides Free Youtube Uploader(it cant's run in my computer,.net framework fault)?thanks,squidge

  6. #6
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: youtube upload

    I would try sending "Content-Type: video/mp4" rather than "Content-Type: video/*", as you are sending, not receiving.

  7. #7
    Join Date
    Oct 2010
    Posts
    11
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: youtube upload

    squidge, i try to send video/mpeg ,video/mp4 ,not result anybody can upload video to youtube from qt app?

  8. #8
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: youtube upload

    Ah, you didn't say that in your original post.

    Looking at your code, your "Content-length" field looks incorrect too. That is supposed to be the length of the entire post body, where as you have it only being the length of the binary data part.

  9. #9
    Join Date
    Oct 2010
    Posts
    11
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: youtube upload

    I try set content lenght after request body filling (request.setRawHeader("Content-lenght",QString::number(reqString.length()).toStdS tring().c_str()))),not result

  10. #10
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: youtube upload

    Then you'll need to fix your .net fault and compare the two wireshark traces, I'm out of ideas.

  11. #11
    Join Date
    Oct 2010
    Posts
    11
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: youtube upload

    squidge,i fix it,but free youtube uploader doesn't work toonow i'm downloading directx sdk,there is an youtube upload example in it

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: youtube upload

    I'm pretty sure that YouTube API will be setting some cookies while sending replies to you so you need to attach a cookie jar to your QNAM to make sure you send those cookies back with queries that follow. Also try to rely on Qt where possible - don't set content-length yourself at all, QNAM will do this for you. Furthermore don't assemble the xml yourself, use QDomDocument or any other available Qt xml writer so that you don't make any mistakes when creating the request. Next, make sure you don't add any incorrect data to the binary stream - I'm not sure your binary data should be surrounded by \r\n, check that this is really how it should be. Also try changing the binary encoding to base64, it will be easier for you to debug although the volume will double.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #13
    Join Date
    Oct 2010
    Posts
    11
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: youtube upload

    i fix the bad request,new request code:
    Qt Code:
    1. request.setUrl(QUrl("http://uploads.gdata.youtube.com/feeds/api/users/default/uploads"));
    2. request.setRawHeader("Host","uploads.gdata.youtube.com");
    3. request.setRawHeader("Authorization","GoogleLogin auth="+auth);
    4. request.setRawHeader("GData-Version","2");
    5. request.setRawHeader("X-GData-Key","key=AI39si53w0jmcZxorzxniPVD_rGBRZJhShx6Bh7uKy-JmAn--BAKzINwR3lNzvOtqnClFlCRiXsk-j8UMaE-EAO9U-7EsDJRxg");
    6. request.setRawHeader("Slug","C:\\qwerty.avi");
    7. request.setRawHeader("Content-Type","multipart/related; boundary=\"f93dcbA3\"");
    8. request.setRawHeader("Connection","close");
    9. QByteArray reqString;
    10. reqString.append("--f93dcbA3\r\n");
    11. reqString.append("Content-Type: application/atom+xml; charset=UTF-8\r\n");
    12. reqString.append("\r\n");
    13. reqString.append("<?xml version=\"1.0\"?>\r\n");
    14. reqString.append("<entry xmlns=\"http://www.w3.org/2005/Atom\"\r\n");
    15. reqString.append("xmlns:media=\"http://search.yahoo.com/mrss/\"\r\n");
    16. reqString.append("xmlns:yt=\"http://gdata.youtube.com/schemas/2007\">\r\n");
    17. reqString.append("<media:group>\r\n");
    18. reqString.append("<media:title type=\"plain\">Test test</media:title>\r\n");
    19. reqString.append("<media:description type=\"plain\">\r\n");
    20. reqString.append("Batafa\r\n");
    21. reqString.append("</media:description>\r\n");
    22. reqString.append("<media:category ");
    23. reqString.append("scheme=\"http://gdata.youtube.com/schemas/2007/categories.cat\">People\r\n");
    24. reqString.append("</media:category>\r\n");
    25. reqString.append("<media:keywords>ara,arara</media:keywords>\r\n");
    26. reqString.append("</media:group>\r\n");
    27. reqString.append("</entry>\r\n");
    28. reqString.append("--f93dcbA3\r\n");
    29. reqString.append("Content-Type: video/*\r\n");
    30. reqString.append("Content-Transfer-Encoding: binary\r\n");
    31. reqString.append("\r\n");
    32. reqString.append(fileBinaryData.toBase64());
    33. reqString.append("\r\n");
    34. reqString.append("--f93dcbA3\r\n");
    35. request.setRawHeader("Content-Length",QString::number(reqString.length()).toUtf8());
    To copy to clipboard, switch view to plain text mode 

    now video upload to server,but youtube say that can't convert video
    Last edited by ernie; 13th December 2010 at 10:43.

  14. #14
    Join Date
    Oct 2010
    Posts
    11
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: youtube upload

    i finished,work fine.Thanks squidge and wysota for replies.
    Work sourcecode for second request:
    Qt Code:
    1. QFile f("C:\\video.avi"); //video file
    2. f.open(QIODevice::ReadOnly);
    3. QByteArray fileBinaryData = f.readAll();
    4. f.close();
    5. QNetworkRequest request;
    6. request.setUrl(QUrl("http://uploads.gdata.youtube.com/feeds/api/users/default/uploads"));
    7. request.setRawHeader("Host","uploads.gdata.youtube.com");
    8. request.setRawHeader("Authorization","GoogleLogin auth="+auth);
    9. request.setRawHeader("GData-Version","2");
    10. request.setRawHeader("X-GData-Key","key=devkey");
    11. request.setRawHeader("Slug","C:\\video.avi");
    12. request.setRawHeader("Content-Type","multipart/related; boundary=\"f93dcbA3\"");
    13. request.setRawHeader("Connection","close");
    14. QByteArray reqString;
    15. reqString.append("--f93dcbA3\r\n");
    16. reqString.append("Content-Type: application/atom+xml; charset=UTF-8\r\n");
    17. reqString.append("\r\n");
    18. reqString.append("<?xml version=\"1.0\"?>\r\n");
    19. reqString.append("<entry xmlns=\"http://www.w3.org/2005/Atom\"\r\n");
    20. reqString.append("xmlns:media=\"http://search.yahoo.com/mrss/\"\r\n");
    21. reqString.append("xmlns:yt=\"http://gdata.youtube.com/schemas/2007\">\r\n");
    22. reqString.append("<media:group>\r\n");
    23. reqString.append("<media:title type=\"plain\">Test</media:title>\r\n");
    24. reqString.append("<media:description type=\"plain\">\r\n");
    25. reqString.append("Batafa\r\n");
    26. reqString.append("</media:description>\r\n");
    27. reqString.append("<media:category ");
    28. reqString.append("scheme=\"http://gdata.youtube.com/schemas/2007/categories.cat\">People\r\n");
    29. reqString.append("</media:category>\r\n");
    30. reqString.append("<media:keywords>ara,arara</media:keywords>\r\n");
    31. reqString.append("</media:group>\r\n");
    32. reqString.append("</entry>\r\n");
    33. reqString.append("--f93dcbA3\r\n");
    34. reqString.append("Content-Type: video/mpeg\r\n");
    35. reqString.append("Content-Transfer-Encoding: binary\r\n");
    36. reqString.append("\r\n");
    37. reqString.append(fileBinaryData);
    38. reqString.append("\r\n");
    39. reqString.append("--f93dcbA3\r\n");
    40. request.setRawHeader("Content-Length",QString::number(reqString.length()).toUtf8());
    41. netmen2 = new QNetworkAccessManager();
    42. QNetworkReply *rep=netmen2->post(request,reqString);
    43. connect(netmen2, SIGNAL(finished(QNetworkReply*)), this, SLOT(handleUploadReply(QNetworkReply*)));
    To copy to clipboard, switch view to plain text mode 

  15. #15

    Default Re: youtube upload

    Hi everyone,

    I am new to QT & c++, i do have a requirement for uploading videos on youtube using API. I have tried to implement the logic, but it always gives me build errors.
    I kindly request to help me with the working .zip file or the instructions which help me to upload a video file to youtube using QT.

    Thanks in advance,
    Suresh.

  16. #16
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: youtube upload

    You have not provided any error message nor your non-working ZIP.

    Cheers,
    _

Similar Threads

  1. play a video from youtube
    By graciano in forum Qt Programming
    Replies: 2
    Last Post: 13th July 2011, 08:17
  2. need help youtube APIs with qt
    By doforumda in forum Newbie
    Replies: 5
    Last Post: 18th November 2010, 21:09
  3. Downloading a video from youtube
    By Faster in forum Qt Programming
    Replies: 21
    Last Post: 28th November 2009, 13:46
  4. upload movie files to youtube
    By jay in forum Qt Programming
    Replies: 0
    Last Post: 21st September 2009, 13:34
  5. Replies: 0
    Last Post: 29th May 2009, 14:00

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.