iOS App with YouTube Uploading Error

377 views
Skip to first unread message

Marcos Jesús Vivar

unread,
Apr 25, 2011, 1:12:55 PM4/25/11
to gdata-objec...@googlegroups.com
Hi everyone,

I'm writing a small iOS App that should upload a video to a YouTube user's account.

I've used the YouTube desktop example and adapted it to the iOS available objects.
The app actually compiles and behaves properly. However when I get to the point of UPLOADING the video, it throws me the same error over and over again:

serviceBase:<GDataServiceGoogleYouTube: 0x783de30> objectFetcher:<GDataHTTPUploadFetcher: 0x78520b0> failedWithStatus:400 data:<errors xmlns='http://schemas.google.com/g/2005'><error><domain>GData</domain><code>InvalidRequestUriException</code><internalReason>Missing or invalid username.</internalReason></error></errors>


When I call the method that instantiates the GDataEntryYouTubeUpload,

- (IBAction)uploadClicked:(id)sender

everything seems to work fine and perfectly settled.

Any thoughts would be appreciated.

Marcos Jesús Vivar
iOS Developer

Greg Robbins

unread,
Apr 25, 2011, 2:43:03 PM4/25/11
to gdata-objec...@googlegroups.com
There's no relevant code snippet or http request/response log in your message, but my first guess is that the service object being used to insert the entry for upload does not have the user credentials (email and password) set.

Marcos Jesús Vivar

unread,
Apr 25, 2011, 3:02:01 PM4/25/11
to gdata-objec...@googlegroups.com
Hi Greg,

This is how I modified the GDataServiceGoogleYouTube constructor:

- (GDataServiceGoogleYouTube *)youTubeService

{    

    static GDataServiceGoogleYouTube* service = nil;

    

    if (!service) 

    { service = [[GDataServiceGoogleYouTube alloc] init];

        

      [service setShouldCacheDatedData:YES];

      [service setServiceShouldFollowNextLinks:YES];

      [service setIsServiceRetryEnabled:YES];

    }


    NSString *username = [kYoutubeUsername retain];

    NSCharacterSet *whitespace = [NSCharacterSet whitespaceAndNewlineCharacterSet];

    kYoutubeUsername = [username stringByTrimmingCharactersInSet:whitespace];

  if ([kYoutubeUsername rangeOfString:@"@"].location == NSNotFound)

    { kYoutubeUsername = [kYoutubeUsername stringByAppendingString:@"@gmail.com"]; }

    

    if (([kYoutubeUsername length] > 0) && ([kYoutubePassword length] > 0))

    { [service setUserCredentialsWithUsername:[kYoutubeUsername retain] password:[kYoutubePassword retain]]; }

    else

    { [service setUserCredentialsWithUsername:nil password:nil]; }

    

    [service setYouTubeDeveloperKey:DEVELOPER_KEY];

    

    return service;

}


And the (NSString *) objects "kYoutubeUsername" and "kYoutubePassword" are set as: 


kYoutubeUsername = mUsernameField.text;

kYoutubePassword = mPasswordField.text;


This is done in another method, prior to showing the UITextFields with required GDataYouTubeMediaGroup fields such as: Title, Description, Category, Keywords, and if it's a private entry or not.


This is the actual definition of "kYoutubeUsername" and "kYoutubePassword":


@interface YoutubeController : UIViewController

{

    /*.

    . Other definitions

    .*/

    

    NSString *kYoutubeUsername;

    NSString *kYoutubePassword;

}


I tried to look at the obvious reasons why this might not work out but it seems that I'm missing something of a sneaky nature.

With this further information, What would be your second guess?

Thanks in advance!

Greg Robbins

unread,
Apr 25, 2011, 4:37:36 PM4/25/11
to gdata-objec...@googlegroups.com
Have you looked at the value of the username and password variables in the debugger at the point where setUserCredentialsWithUsername:password: is called?

Incidentally, the Cocoa convention is that the receiving methods retains or copies its parameters if necessary, so the caller never needs to retain them.

Marcos Jesús Vivar

unread,
Apr 25, 2011, 5:22:05 PM4/25/11
to gdata-objec...@googlegroups.com
Yes,

I have looked at those values several times (including NSLogging them) and they are perfectly set.

I wonder what it's the main difference with the exampled code for YouTube:

- (IBAction)uploadClicked:(id)sender

{

    [mUploadProgressView setHidden:NO];

    

    GDataServiceGoogleYouTube *service = [self youTubeService];

    [service setYouTubeDeveloperKey:DEVELOPER_KEY];

    

    NSString *username = kYoutubeUsername;

    

    NSURL *url = [GDataServiceGoogleYouTube youTubeUploadURLForUserID:username];

    

    // load the file data

    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"100_1142" ofType:@"mov"];

    

    NSData *data = [NSData dataWithContentsOfFile:filePath];

    NSString *filename = [filePath lastPathComponent];

    

    // gather all the metadata needed for the mediaGroup

    NSString *titleStr = mTitleField.text;

    GDataMediaTitle *title = [GDataMediaTitle textConstructWithString:titleStr];

    

    GDataMediaCategory *category = [GDataMediaCategory mediaCategoryWithString:@"Entertainment"];

    [category setScheme:kGDataSchemeYouTubeCategory];

    

    NSString *descStr = mDescriptionField.text;

    GDataMediaDescription *desc = [GDataMediaDescription textConstructWithString:descStr];

    

    NSString *keywordsStr = mKeywordsField.text;

    GDataMediaKeywords *keywords = [GDataMediaKeywords keywordsWithString:keywordsStr];

    

    BOOL isPrivate = ([mPrivateSwitch state] == YES);

    

    GDataYouTubeMediaGroup *mediaGroup = [GDataYouTubeMediaGroup mediaGroup];

    [mediaGroup setMediaTitle:title];

    [mediaGroup setMediaDescription:desc];

    [mediaGroup addMediaCategory:category];

    [mediaGroup setMediaKeywords:keywords];

    [mediaGroup setIsPrivate:isPrivate];

    

    NSString *mimeType = [GDataUtilities MIMETypeForFileAtPath:filePath

                                               defaultMIMEType:@"video/mov"];

    

    // create the upload entry with the mediaGroup and the file data

    GDataEntryYouTubeUpload *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];

    

    [self updateUI];

}


Since we're developing we have hardcoded the category (an existing one) and the video file (added to the project) as you can see.

Any idea that the group may have is going to be kindly received!

Greg Robbins

unread,
Apr 25, 2011, 5:28:11 PM4/25/11
to gdata-objec...@googlegroups.com
Use kGDataServiceDefaultUser for the username when constructing the upload URL.

Try turning on logging with [GDataHTTPFetcher setIsLoggingEnabled:YES] and looking at the request/response that is failing in the logs.

The error "Missing or invalid username" implies something fundamental is wrong, either with the Authentication header of the upload request, or with the upload URL.

MOHIT MASKE

unread,
Sep 8, 2012, 3:56:36 AM9/8/12
to gdata-objec...@googlegroups.com



Hi everyone,

I'm writing a small iOS App that should upload a video to a YouTube user's account.

   I'am added file gdata in my video sense app file so some error will be created..

 
I've used the YouTube desktop example and adapted it to the iOS available objects.
The app actually compiles and behaves properly. However when I get to the point of UPLOADING the video, it throws me the same error over and over again:

serviceBase:<GDataServiceGoogleYouTube: 0x783de30> objectFetcher:<GDataHTTPUploadFetcher: 0x78520b0> failedWithStatus:400 data:<errors xmlns='http://schemas.google.com/g/2005'><error><domain>GData</domain><code>InvalidRequestUriException</code><internalReason>Missing or invalid username.</internalReason></error></errors>

 and another error on my video sense application so file not found error and also autorelease error in my app so what can i do in my solve all error in my videosense app so please help me solving error...

Reply all
Reply to author
Forward
0 new messages