Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upload video on youtube from iphone app

I want to upload video on youtube from my iphone app.. I have tried this http://urinieto.com/2010/10/upload-videos-to-youtube-with-iphone-custom-app/ but in the end i am getting error Domain=com.google.GDataServiceDomain Code=400 "The operation couldn’t be completed. (com.google.GDataServiceDomain error 400.)" UserInfo=0x4d921f0 {}

Can any one help me. Thanx!!!

My code

 NSString *devKey = [mDeveloperKeyField text];

    GDataServiceGoogleYouTube *service = [self youTubeService];
    [service setYouTubeDeveloperKey:devKey];

    NSString *username = [mUsernameField text];
    NSString *clientID = [mClientIDField text];

    NSURL *url = [GDataServiceGoogleYouTube youTubeUploadURLForUserID:username
                                                             clientID:clientID];

    // load the file data
    NSString *path = [[NSBundle mainBundle] pathForResource:@"YouTubeTest" ofType:@"m4v"]; 
    NSData *data = [NSData dataWithContentsOfFile:path];
    NSString *filename = [path lastPathComponent];

    // gather all the metadata needed for the mediaGroup
    NSString *titleStr = [mTitleField text];
    GDataMediaTitle *title = [GDataMediaTitle textConstructWithString:titleStr];

    NSString *categoryStr = [mCategoryField text];
    GDataMediaCategory *category = [GDataMediaCategory mediaCategoryWithString:categoryStr];
    [category setScheme:kGDataSchemeYouTubeCategory];

    NSString *descStr = [mDescriptionField text];
    GDataMediaDescription *desc = [GDataMediaDescription textConstructWithString:descStr];

    NSString *keywordsStr = [mKeywordsField text];
    GDataMediaKeywords *keywords = [GDataMediaKeywords keywordsWithString:keywordsStr];

    BOOL isPrivate = mIsPrivate;

    GDataYouTubeMediaGroup *mediaGroup = [GDataYouTubeMediaGroup mediaGroup];
    [mediaGroup setMediaTitle:title];
    [mediaGroup setMediaDescription:desc];
    [mediaGroup addMediaCategory:category];
    [mediaGroup setMediaKeywords:keywords];
    [mediaGroup setIsPrivate:isPrivate];

    NSString *mimeType = [GDataUtilities MIMETypeForFileAtPath:path
                                               defaultMIMEType:@"video/mp4"];

    // create the upload entry with the mediaGroup and the file data
    GDataEntryYouTubeUpload *entry;
    entry = [GDataEntryYouTubeUpload uploadEntryWithMediaGroup:mediaGroup
                                                          data:data
                                                      MIMEType:mimeType
                                                          slug:filename];

    SEL progressSel = @selector(ticket:hasDeliveredByteCount:ofTotalByteCount:);
    [service setServiceUploadProgressSelector:progressSel];

    GDataServiceTicket *ticket;
    ticket = [service fetchEntryByInsertingEntry:entry
                                      forFeedURL:url
                                        delegate:self
                               didFinishSelector:@selector(uploadTicket:finishedWithEntry:error:)];

    [self setUploadTicket:ticket];
like image 974
Surender Rathore Avatar asked May 29 '12 14:05

Surender Rathore


People also ask

Why can't I upload a video to YouTube from my iPhone?

Google specifies that you need to be verified with their service in order to upload long videos (over 15 minutes), which may be causing the uploads from your iPhone to stop.

Can you upload YouTube videos from the mobile app?

Use the YouTube Android app to upload videos by recording a new video or selecting an existing one. Get the latest news, updates, and tips on the YouTube Creators channel. Open the YouTube app . Upload a video.


1 Answers

First things first, check the YouTube API for any updates to it's GData libraries, (they changed last I used them and broke my app).

http://apiblog.youtube.com/2009/02/youtube-apis-iphone-cool-mobile-apps.html

Next, check for silly stuff. Got all your headers imported, everything checks out, etc?

Try setting your info.plist to use Wi-Fi, I've heard some of the new GData API's look for that might explain your 400 error, your app might not be pinging the YouTube servers.

like image 89
Chad Adams Avatar answered Sep 20 '22 15:09

Chad Adams