ios - Upload video on youtube from iphone app

I want to upload video on youtube from my iphone app.. I have tried this but in the end i am getting error Code=400 "The operation couldn’t be completed. ( 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

    // 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

    // create the upload entry with the mediaGroup and the file data
    GDataEntryYouTubeUpload *entry;
    entry = [GDataEntryYouTubeUpload uploadEntryWithMediaGroup:mediaGroup

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

    GDataServiceTicket *ticket;
    ticket = [service fetchEntryByInsertingEntry:entry

    [self setUploadTicket:ticket];

1 Answer

  1. Justin- Reply


    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).

    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.

Leave a Reply

Your email address will not be published. Required fields are marked *

You can use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>