verifying YouTube log-in from iphone app

Discussion in 'iOS Programming' started by gbenna, Dec 26, 2012.

  1. gbenna macrumors member

    Jul 27, 2011
    I have an app in which the user uploads a video to youtube. I have the user input their password and username to sign in and then they input the "title", "description", "tags", "category", and "privacy setting" i.e. public, private, unlisted. All works well. However I am not able to verify that the password for the given username is valid or even if the username is valid. When the password and username are filled in and the "sign in" button is tapped these are saved into the documents directory as password.txt and username.txt. Then these are used to complete the process and in fact loaded from the documents directory upon subsequent uploads until the user signs out, in which case the files are removed.
    My problem is I would like to check with YouTube when the user fills in the password and username and goes to save them to make sure they are valid. Can someone help me with this.

    This is the code I use to input the username and password as well as developers key to YouTube to get a service to allow uploading video.

    - (GDataServiceGoogleYouTube *)youTubeService {
        static GDataServiceGoogleYouTube* service = nil;
        if (!service) {
            service = [[GDataServiceGoogleYouTube alloc] init];
            [service setShouldCacheResponseData:YES];
            [service setServiceShouldFollowNextLinks:YES];
            [service setIsServiceRetryEnabled:YES];
            /*[service setUserCredentialsWithUsername:accountView.text password:PasswordDisplayField.text];*/
        NSString *username = [accountView.text retain];
        NSCharacterSet *whitespace = [NSCharacterSet whitespaceAndNewlineCharacterSet];
        accountView.text = [username stringByTrimmingCharactersInSet:whitespace];
        /*if ([accountView.text rangeOfString:@"@"].location == NSNotFound)
        { accountView.text = [kYoutubeUsername stringByAppendingString:@""]; }*/
        if (([accountView.text length] > 0) && ([PasswordDisplayField.text length] > 0))
        { [service setUserCredentialsWithUsername:[accountView.text retain] password:[PasswordDisplayField.text retain]]; }
        { [service setUserCredentialsWithUsername:nil password:nil]; }
        [service setYouTubeDeveloperKey:devKey];
        return service;
    and then I use this code to get the URL for uploading

    NSURL *url = [GDataServiceGoogleYouTube youTubeUploadURLForUserID:kGDataServiceDefaultUser];

    but I am not sure how to use these to check to see if the username and password are matched and compatible and return an error message is they are not . Also I don't want to save them if they are not correct.

    If someone can suggest a solution, a tutorial, video or something else to help me accomplish this I would greatly appreciate it.

  2. ArtOfWarfare, Dec 27, 2012
    Last edited: Dec 27, 2012

    ArtOfWarfare macrumors G3


    Nov 26, 2007
    1 - Is saving the password like that really the best idea? It seems like a fairly large security risk... If someone plugs their iOS device into a compromised computer, it could scan all of the iOS device's documents and send them off, could it not? And actually, is iTunes able to read the document from its iOS document sync tab? Your YouTube account is synced with all your other Google Services, including GMail, Google Drive, Google+, which seems like they could contain very important and very private information.

    Use Keychain instead to store the username and password:

    2 - I haven't used Google's YouTube APIs, but I'd imagine they include some delegate method indicating whether an upload finished successfully or not.

    Edit: It looks like maybe Google doesn't have an iOS YouTube API anymore and now they expect you to use the JavaScript API instead?

    This is a bit dated (from 2008) and doesn't show uploading as far as I can tell, but they do include using OAuth 2.0 to login, so you might find this sample code from Google helpful:
  3. gbenna thread starter macrumors member

    Jul 27, 2011
    I have changed my code to put the password into the keychain and that works fine. I looked at the site you referenced but when I went to use it they were various errors. I am trying to use Client log in which is depricated for now but will work until 2015. So I would like to use it and get this up and running and then work on updating to Auth3 or whatever they come up with by then. I see there is YouTubeRequestSettings which equates the client id, developer code, username and password. But now I am looking for how to use it. I find this very frustrating as I have everything working. The video, title, description, tags, privacy. Everything works great so long as the correct username and password are typed in. Why is it so difficult to find somewhere where this is documented on how to do. Sorry I'm just frustrated. Thanks

Share This Page