Results 1 to 16 of 16

Thread: youtube upload

Hybrid View

Previous Post Previous Post   Next Post Next Post
  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 15: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

Similar Threads

  1. play a video from youtube
    By graciano in forum Qt Programming
    Replies: 2
    Last Post: 13th July 2011, 07:17
  2. need help youtube APIs with qt
    By doforumda in forum Newbie
    Replies: 5
    Last Post: 18th November 2010, 20:09
  3. Downloading a video from youtube
    By Faster in forum Qt Programming
    Replies: 21
    Last Post: 28th November 2009, 12:46
  4. upload movie files to youtube
    By jay in forum Qt Programming
    Replies: 0
    Last Post: 21st September 2009, 12:34
  5. Replies: 0
    Last Post: 29th May 2009, 13: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
  •  
Qt is a trademark of The Qt Company.