objective c - iOS YouTube Video Upload Error -


i trying upload video using objective-c , youtube api not working , return error @ last step. error reads "user authentication required".

i following api document 1 without metadata. got authentication token clientlogin api

i checked authentication token nslog , it's there. see upload api returns upload url when send http put request retrieved upload url, returns error mentioned above.

here's upload code

- (bool) upload:(nsstring *)file {     nsdata *filedata = [nsdata datawithcontentsoffile:file];      nsurl *url = [nsurl urlwithstring:self.uploadurl];      nsmutableurlrequest *request = [nsmutableurlrequest requestwithurl:url];      [request sethttpmethod:@"put"];     [request setvalue:@"content-type" forhttpheaderfield:@"application/octet-stream"];     [request setvalue:@"content-length" forhttpheaderfield:[nsstring stringwithformat:@"%ud", [filedata length]]];     [request sethttpbody:filedata];      nserror *requesterror;     nsurlresponse *urlresponse = nil;      nsdata *response = [nsurlconnection sendsynchronousrequest:request returningresponse:&urlresponse error:&requesterror];      nslog(@"%@", [[nsstring alloc] initwithdata:response encoding:nsutf8stringencoding]);      if (response == nil) {         return no;     } else {         return yes;     } } 

i tried direct upload method gives me invalid request error. below code.

- (bool) directupload:(nsstring *)file {     nsstring *title = [file lastpathcomponent];     nsstring *desc = @"this test video.";     nsstring *category = @"people";     nsstring *keywords = @"video";      nsstring *boundary = @"--qwerty";      nsstring *xml = [nsstring stringwithformat:                      @"<?xml version=\"1.0\"?>"                      @"<entry xmlns=\"http://www.w3.org/2005/atom\" xmlns:media=\"http://search.yahoo.com/mrss/\" xmlns:yt=\"http://gdata.youtube.com/schemas/2007\">"                      @"<media:group>"                      @"<media:title type=\"plain\">%@</media:title>"                      @"<media:description type=\"plain\">%@</media:description>"                      @"<media:category scheme=\"http://gdata.youtube.com/schemas/2007/categories.cat\">%@</media:category>"                      @"<media:keywords>%@</media:keywords>"                      @"</media:group>"                      @"</entry>", title, desc, category, keywords];      nsdata *filedata = [nsdata datawithcontentsoffile:file];      nsmutabledata *postbody = [nsmutabledata data];     [postbody appenddata:[[nsstring stringwithformat:@"%@\n", boundary] datausingencoding:nsutf8stringencoding]];     [postbody appenddata:[[nsstring stringwithformat:@"content-type: application/atom+xml; charset=utf-8\n\n"] datausingencoding:nsutf8stringencoding]];     [postbody appenddata:[xml datausingencoding:nsutf8stringencoding]];     [postbody appenddata:[[nsstring stringwithformat:@"%@\n", boundary] datausingencoding:nsutf8stringencoding]];     [postbody appenddata:[[nsstring stringwithformat:@"content-type: video/mp4\n"] datausingencoding:nsutf8stringencoding]];     [postbody appenddata:[[nsstring stringwithformat:@"content-transfer-encoding: binary\n\n"] datausingencoding:nsutf8stringencoding]];     [postbody appenddata:filedata];     [postbody appenddata:[[nsstring stringwithformat:@"%@", boundary] datausingencoding:nsutf8stringencoding]];      nsurl *url = [nsurl urlwithstring:@"http://uploads.gdata.youtube.com/feeds/api/users/default/uploads"];      nsmutableurlrequest *request = [nsmutableurlrequest requestwithurl:url];      [request sethttpmethod:@"post"];     [request setvalue:[nsstring stringwithformat:@"googlelogin auth=\"%@\"", self.authtoken] forhttpheaderfield:@"authorization"];     [request setvalue:@"2" forhttpheaderfield:@"gdata-version"];     [request setvalue:[nsstring stringwithformat:@"key=%@", self.developerkey] forhttpheaderfield:@"x-gdata-key"];     [request setvalue:[file lastpathcomponent] forhttpheaderfield:@"slug"];     [request setvalue:[nsstring stringwithformat:@"multipart/related; boundary=\"%@\"", boundary] forhttpheaderfield:@"content-type"];     [request setvalue:[nsstring stringwithformat:@"%ud", [postbody length]] forhttpheaderfield:@"content-length"];     [request setvalue:@"close" forhttpheaderfield:@"connection"];     [request sethttpbody:postbody];      nserror *requesterror;     nsurlresponse *urlresponse = nil;      nsdata *response = [nsurlconnection sendsynchronousrequest:request returningresponse:&urlresponse error:&requesterror];      nslog(@"%@", [[nsstring alloc] initwithdata:response encoding:nsutf8stringencoding]);      if (response == nil) {         return no;     } else {         return yes;     } } 

i think should check :-

https://developers.google.com/youtube/2.0/developers_guide_protocol_video_feeds

and check :-

http://urinieto.com/2010/10/upload-videos-to-youtube-with-iphone-custom-app/


Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -