YouTube API on iOS : Uploading a video

Update: If you are only targeting iOS 8, I have created a Framework bundle to make things simpler. 

As straightforward as it may seem, one can get lost trying to get their app to use the YouTube API. This tutorial will explain how to use the API to get a list of videos in a playlist and  then upload a video right from our app!

These are the basic steps we will be following:

0. Create a iOS project in Xcode.
1. Register an App with Google.
2. Get the YouTube Data API.
3. Integrate the API into your project.
4. Configure the API for your Google App.
5. Use the API to get Playlist data and upload a video.

A lot to cover, lets get started.

0. Create a iOS project in Xcode.
Obviously we will need a iOS project. So go ahead and create a new iOS project in Xcode. Note the bundle ID of the project from the plist file, we will need this later.

1. Register an App with Google.
We need to register an application with Google. This is needed so the API requests coming to YouTube from your App can be identified. It is pretty straightforward. Firstly, you will need a google account. Then head over to Google Developers Console.

1. Create project

Here you will see a projects tab with a ‘ CREATE PROJECT’ button, click it. This will present you with a window where you need to provide some project details. First is Project Name, self explanatory. Next is Project ID which is auto-generated but can be changed. However it needs to be unique globally! I suggest you use the one provided by default as its not visible to the end user anyway. Read and accept the Terms of Service to continue.

2. Project Details

If the information you provided was valid, you should be redirected to your Project’s page. Note that this may take some time while your project request is being approved. Click on the ‘APIs and Auth’ tab and then select ‘Credentials’. You should see a OAuth section with Client ID and Email Address. However these are not the credentials we are interested in. We need credentials for a native app. Click the ‘CREATE NEW CLIENT ID’ button.

3. Project Credentials

In the Create Client ID window, select ‘Installed application’, followed by ‘iOS’ for type. Next you will need to provide your Application’s Bundle ID, this is found in the .plist file of your project or in the Project settings window under General.

4. New Client ID

Hit Create button to register. You will get a new Client ID and Client secret, this is what we will need later.

5. New Client ID created

2. Get the YouTube Data API
At the time of writing this tutorial the latest version of Google Data API was ‘v3’. The first thing we will need to do is download the objective-C client library. We will check out the svn repository. Open up Terminal and move to the directory where you want to place this downloaded code. To check out the code use this command in Terminal:

svn checkout google-api-objectivec-client-read-only

*In case this does not work for some reason, you can get the latest url here.

This will create a ‘google-api-objectivec-client-read-only‘ directory at the location you chose.

3. Integrate the API into your project.

There are 3 ways to integrate the client library into your project: as a iOS static library, as a framework or directly by including source files. I have found the last option to be most convinent and thats what I will be using in this tutorial.

In case you want to use a different approach, this link will be helpful.

We will need to include a bunch of files into the project. Create a new group within the project, (mine is called ‘Google-API-Stuff’) to put all these files in.

3.1 Add the ‘GTLCommon_Sources.m’ and ‘GTLNetworking_Sources.m’ files to your project.
Open the downloaded client API folder we just checked out. Open the ‘Source’ folder. Here you should see these two files. Copy them into your project, under the new group we just created. Make sure you DO NOT select the ‘Copy items into destination group’s folder’ option.

6. Add 2 source files

3.2 Adding library’s source folders to Header Search Paths.
This one requires some work. What will do here is tell Xcode where to find the relevant files for the Google API from our machine instead of copying it into our project.

7. Add search paths

a) In Xcode navigator select your project file.
b) Make sure you have the project selected and not the target.
c) Click the ‘Build Settings’ tab.
d) In the search box, type ‘Header Search Paths’
e) You should now see the entry for ‘Header Search Paths’ below. Double click it to open the edit window.
f) You can click the little ‘+’ button at the bottom to add the paths required.
8. Add values to header search paths
g) We need to add the FULL paths for the following folders:


For example in my case the paths are:


9. Added paths

h) Now that we have added the common files required for the API, we will need to repeat the above steps for the particular google service we wish to use, in our case YouTube :]

Open the downloaded client API folder again and navigate to Source/Services/YouTube/Generated.

From here copy the ‘GTLYouTube_Sources.m’ to your project group where we placed the previous copied files.

10. Add _sources file

Next we will need to add this path to the Header Search Paths like we did earlier. This time the folder we need is:


In my case the full path is:


3.3 Add OAuth 2 sign-in view.
YouTube services require OAuth to establish a secure connection with the client. We need to add this view to our project as well. In the client API folder, navigate to:

Here you will see GTMOAuth2ViewTouch.xib.
Copy it into your project as well.

11. Add OAuth controllers

3.4 Add required frameworks
We need to following frameworks linked to our project.
a) Security.framework
b) SystemConfiguration.framework

12. Adding Frameworks

3.5 ARC
In case you are using ARC, which you should, you will need to perform another step. The API files we are compiling do not use ARC while our project does. Therefore we will need to specifically tell Xcode to treat these files as ‘not using ARC’ .

Head over to the Build Phases of your target. Here under compile sources, you should see the three API .m files we added to our project along with other files from our project. We need to add a flag to these three files to mark them as non ARC. Double click a file, this will open a window, insert the following flag:
Do this for all the three files (GTLCommon_Sources.m, GTLNetworking_Sources.m, GTLYouTube_Sources.m).

13. Adding no ARC flag

This should do it! Our project is now ready to link with the API. Build project, there should be no errors.

4. Configure the API for your Google App.

Basically our App is now ready to talk to YouTube. All we have to do is authenticate and then call appropriate API functions to get/send data. To authenticate we will need the Client ID and Client Secret that we got earlier. After this, the user will need to log into her/his google account and provide permission to our app to use YouTube on their behalf.

Though this process is not very complicated it get a little confusing at first. I wrote a simple wrapper class when I was working with this API. Please use it for now to make things easier. Later you can modify it or write your own class for any particular requirement. Download the YouTubeHelper here. Add the YouTubeHelper.h and YouTubeHelper.m files to your project.

To work with YouTubeHelper, include the ‘YouTubeHelper.h’ file into your viewController. Your class will also need to conform to the YouTubeHelperDelegate protocol.

#import <UIKit/UIKit.h>
#import "YouTubeHelper.h"
@interface ViewController : UIViewController

The protocol has some mandatory methods:

- (NSString *)youtubeAPIClientID;
Here you will provide your app’s Client ID that we got from the Google Developer Console earlier.

- (NSString *)youtubeAPIClientSecret;
Here you will provide the Client Secret.

- (void)showAuthenticationViewController:(UIViewController *)authView;
When the OAuth process starts, the API needs to present its view controller to the user. YouTubeHelper calls this delegate method and provides you with the viewController to be displayed. It is then your responsiblity to push/present this.

- (void)authenticationEndedWithError:(NSError *)error;
After authentication this delegate is called. If the error is nil, it means the authentication was successfull.

Ok done, now what? After implemeting the delegates, its time to start using the API.

Inside your class create an object of the YouTubeHelper class using the initWithDelegate: method. Now that you have an instance of this object, you can use it to authenticate, get uploaded videos playlist and upload a video.

1) Authenticate:

User will need to authenticate the application for the first use. After auth the information is stored in user’s keychain and can be reused on subsequent runs.

To authenticate, call the
- (void)authenticate;
method on YouTubeHelper object. This will be followed by the two delegate methods disscussed earlier being called.

In case the user wishes to sign out, call the
- (void)signOut;
method. This will delete the auth info stored in keychain.

2) Getting uploaded playlist:

If the authentication is done, we can now finally get some useful information from youtube. Call the
- (void)getUploadedPlaylist;
method. This will fetch the upload channel and a list of videos uploaded to it. After the data is fetched the
- (void)uploadedVideosPlaylist:(NSArray *)array;
delegate is called. This will return an array of ‘GTLYouTubePlaylistItem’ items. To test this you can print the names of the items using

- (void)uploadedVideosPlaylist:(NSArray *)array;
NSLog(@"uploaded list:");
for (int ii = 0; ii < array.count; ii++) {
GTLYouTubePlaylistItem* item = array[ii];
NSLog(@" %@", item.snippet.title);

Make sure you have a video uploaded on youtube before testing this.

3) Uploading a video.

To upload a video, you will need to call the
- (void)uploadPrivateVideoWithTitle:(NSString *)title
description:(NSString *)description
commaSeperatedTags:(NSString *)tags
andPath:(NSString *)path;


It accepts a title (mandatory), description (optional), tags (optional) and path (mandatory).

You can track the upload progress by implementing the
- (void)uploadProgressPercentage:(int)percentage;

For additional help on using YouTubeHelper check out the demo project. However note that this project will not run on your machine until you set up all the links mentioned above.


74 thoughts on “YouTube API on iOS : Uploading a video

  1. Chandresh Kanetiya says:

    when i get playlist

    display following
    2014-04-30 14:34:31.821 YouTubeUpload[1291:60b] Unable to get channels info

    When i upload the video

    display following
    2014-04-30 14:34:34.201 YouTubeUpload[1291:60b] Data uploaded: 0
    2014-04-30 14:34:34.426 YouTubeUpload[1291:60b] Video Upload failed : (null)

  2. @chandresh: Were you able to authenticate successfully? Make sure you have a valid youtube account. If this is not the problem, please take a look at the sample code at:

    Also please use the latest version of YouTubeHelper.m, I have made a bug fix.

  3. Nikolay Kapustin says:

    Such a great post! Very useful. Thank you very much!

  4. lotfi says:

    thanks you :) :)

  5. Ramakrishna says:

    You are a life saver :)
    I’m facing a problem with authentication. I’m unable to authenticate, The error message just show “(null)” which is printed by -(void)authenticationEndedWithError:(NSError *)error method.

    Could you help me on this?

    • Hi Ramakrishna, a null error in the above method means that the authentication WAS successful actually.

      – (void)authenticationEndedWithError:(NSError *)error;
      After authentication this delegate is called. If the error is nil, it means the authentication was successfull.

  6. Ramakrishna says:

    Well It worked just after a while. I would admit that, by far this is one of the best tutorials to upload videos which has been leveled down to granules to make everyone understand.

    I’ve a doubt on how to upload the recorded videos to the youtube and get the URL right after I upload. Let me know if there is any tutorial from you about this. Thanks in advance.

  7. Thanks for the kind words Rama!

  8. Kang says:

    I want the users to upload their video from their camera library,
    the path I get from another test app is as follows.


    so replaced video path in uploadVideoTapped method with ;
    NSString* videoPath = @”assets-library://asset/asset.MOV?id=1EF7CCB1-35EC-40F1-A8A0-540C6BEC0C36&ext=MOV”;

    but this gives error message “YouTube Helper: invalid/missing file at location”

    how to fix it?

    • Hi Kang, I don’t believe that is a valid way to import a video from users Camera roll. You can use the ‘UIImagePickerController’ to import video into your app.

      • Kang says:

        Hi, Nirbhay Agarwal.

        You’re right.

        What I get from UIImagePickerController is like;
        NSString* videoPath = @”assets-library://asset/asset.MOV?id=1EF7CCB1-35EC-40F1-A8A0-540C6BEC0C36&ext=MOV”;

        I want to upload that video.


  9. James Qiu says:

    Nirbhay, love your tutorial!!!
    Does API support video download? If not, what approach could make it happen?

  10. James Qiu says:

    “There are 3 ways to integrate the client library into your project: as a iOS static library, as a framework or directly by including source files. I have found the last option to be most convinent and thats what I will be using in this tutorial.”
    Could you show briefly how to do the first 2 options? Thanks!

    • Hi James, Glad you found the tutorial helpful.

      Basically the reason I went for the last approach is because thats what worked for me. Now that we have framework support in iOS8, maybe google can release a unified framework for us.

      • James Qiu says:

        Hello Nirbhay,
        This tutorial is all about “YouTube Data API v3”, what about “YouTube Analytics API”? Have you ever experienced that? It looks like only offer downloading “libGoogleAnalyticsServices.a” and copy into our iOS project.


  11. Ramakrishna Vaitla says:

    Hi Nirbhay,

    I tried to authenticate and upload from the same View, all went well. But, when I tried authenticating from one view controller and uploading from another view controller, it says YouTube has not been authenticated to upload the videos. Why is that the session is not accessible from another View Controller?

    • hmmm.. I am not sure how and where I am storing the authentication session details. I will look into the code and see if there is something I can fix. In the mean time please try and take a look at the code yourself and if there is something you can fix please share :)

  12. Bhoomi says:

    Hello Nirbhay,
    Very happy for this helpful tutorial..It really works very well ..I have tried many Github code but i couldn’t got result as i expected..but your code is very pretty and step you have mention very straight forward….Thank you..

    One question,How can i get list of favourite videos…

    If anytime i stuck in some code may i mail you?

    • That means a lot :), thanks!

      My main aim with this tutorial was to get things set up for the app to start talking to the YouTube API, because I think that is the hardest part. I haven’t really looked into implementing all the details.

      I really encourage you to look into my interface(YouTubeHelper) and enhance it the way you want. It would also be great if you could share your code back to help others :)

  13. Robin JR says:

    i have added library source folders to Header Search Paths.
    but it shows an error
    ~uTube/google-api-objectivec-client-read-only/Source/Services/YouTube/Generated/GTLYouTubeConstants.h:34:9: ‘GTLDefines.h’ file not found

  14. arti says:

    Hi Nirbhay thanks for the tutorial it is very useful. but I am facing following issue

    YouTube Helper: Client ID not provided, please implement the required delegate method
    YouTube Helper: Client Secret not provided, please implement the required delegate method

    with the fact I have already added these function definitions.

    can you please help me where am I going wrong?

  15. arti says:

    Yes I am setting helper delegate to self…

  16. Jerry says:

    Hi Nirbhay thanks for the tutorial it is very useful. I am facing following issue.

    When the network is unavailable , the YouTubeHelper will not callback. So what should I do ?

  17. Marlon Ansale says:

    Hi Nirbhay,

    Great tutorial. But I have a problem on uploading the video on youtube the error is:
    “Video Upload failed : (null)”

    I just added the video in my project and try to test upload it on youtube then encounter this problem.

  18. Vishal says:

    GTLCommon_Sources.m ,GTLNetworking_Sources.m and GTLYouTube_Sources.m are missing in you code.
    How do i get above files ?
    I have also downloaded direct-lite-iOS from below Link. but still not file those missing files

  19. Jeff says:

    Great Tutorial. I have one questions though. How do retrieve the url of an uploaded video once it is uploaded.

  20. Antony says:

    Hi Nirbhay,

    Thank you for your great tutorial.Is it possible to avoid the first authentication popup by hardcoding username and password

    • Hi Antony, I don’t really think it is possible to bypass the google authentication page, at least I don’t know of such a way. But once you log in, you can cache the security token and reuse it till it expires.

      • Harikrishna says:

        Hi Nirbhay,
        Is there any possible way to Authenticate with single service account(Google account) instead of asking the end user to login with their account.

        All video’s need to save with one account and end user shouldn’t ask for login to upload.

        Any suggestions will be good.


  21. Pratipalsinh Jadeja says:

    Hi Nirbhay,
    This was the best tutorial i have found on net. thanks a ton for that i have downloaded your project from github using this link

    but as you said i have to download missing youtube api files from
    svn checkout google-api-objectivec-client-read-only

    which i have done as you said
    i have also set new header search path as per my downloaded library but still i am getting various files not found errors

    is there any other way to bypass header search path thing,

    can we create framework for google objective c library & simple import it like Facebook framework?

    please help me ASAP.

    Pratipalsinh Jadeja

    • Hello Pratipalsinh, glad this was helpful!

      @files not found: It has worked for me and others, so unless google has changed something in the repo, it looks like you may have just missed a step. Try retracing the steps once more.

      @framework: Alas google did not take the time to make it easy for the devs to integrate their youtube API, hence this tutorial :). However, with iOS 8 support for Frameworks, I think it would be a good exercise to try and wrap all this up in a framework. Go ahead!

      • Pratipalsinh Jadeja says:

        Hi, Nirbhay,
        Thanks for Quick response.

        Yes i have checked all steps as you said,
        i have been working for this issue almost 20 hours, me & my colleagues are trying to find out why this is not happening but still no luck :(

        i have set header search path exactly as you said.

        i am not copying into my folder just creating reference of those files.

        how many ways that i can use those files in Xcode?

        BTW i am using Xcode 6.1

        is there any change while drag & drop files in Xcode 6?

  22. 20 hours! oh no!

    It maybe an issue with Xcode 6.1, but I am really not sure. Could you also go to Google’s SDK page and try to look at the change log since I posted this tutorial? Maybe something was changed at their end.

    Other than that, I don’t really think I can help. It has been some time since I did this myself. I will spend some time this weekend and try to reimplement this in Xcode 6.1 and tell you if I get any new issues.

  23. Upkesh Thakur says:

    You are a life saver. :)
    But i also want to do with Public API key, so what to do?

  24. […] are only available on iOS 8. If you are targeting a previous versions this link will be […]

  25. jp says:

    having headache because of retrieve user youtube playlist please help me this topic.

    • could you explain your problem further? It looks like you might want to get the updated playlist after uploading a video. If you look inside YouTubeHelper.m, there is already function for that. If its not a part of .h, just copy it to YouTubeHelper.h to call from other classes.

      • Pratipalsinh says:

        Hi Nirbhay,
        Yes, Found my way to upload a video using old gdata upload video which will working but it was deprecated but still works cause i want upload video to specific account & in background without prompting user to authenticate this was only possible with old api.

        cheers for your help

  26. Shorhashi says:

    So helpful, thank you very much.

  27. Sourabh Sharma says:

    Hi Nirbhay,

    Thanks for your detail explanation. But i have a problem regarding creating channel. If user is new to youtube and i does’nt create channel the we can’t upload video to that account. So i am getting error. Now i want to create channel after singIn( if user don’t have single account).

    I hope u will understand my question.

    • Yes I understood your question Sourabh. Unfortunately this was not one my requirements when I wrote my wrapper. I encourage you to take a look at the implementation and figure out what API you can use to create a channel.

      Side note: The API is a bit nasty :(, so be patient and read the google data api documentation.

      • Sourabh Sharma says:

        I asked this question in so many forums but I did’nt get best solution for it. I am new to iOS development and its hard for me to change in the library according to my need. It is too co-related with so many files. If you find any solution for it, Please let me know. Thanks

      • This is not a widely used library and on top of that your use case is even more specific. I doubt you will get a ready made answer anywhere. I dont think that you being new to iOS is the problem here, the Google data library is genuinely difficult to understand.

        I think your best bet is to just bite the bullet and spend time understanding the library. A shortcut would be to look for other apps that do what you want and contact their developers for help.

  28. Sourabh Sharma says:

    I found this functionality in this app. Its a official app of youtube. are their developers help me to create channel in my app?

  29. Abhi Kumar says:

    I have an iOS app which includes sharing links to Google+ and uploading videos on Youtube. First I completed with sharing links on Google+(Followed Post:

    For uploading videos on youtube, I followed your tutorial

    The problem is that Header Files clash giving error “Redefinition of enumerator”

    How do I solve it?


  30. Abhi Kumar says:

    I wish to upload videos in “Unlisted” way not privately. How do I achieve it?

  31. when u get logged into gmail account they give a specific code saying this that paste this code into your application now where exactly should i post this code.
    i mean is this the keychain id or something else?

  32. zennia says:

    When I try to put GTLCommon_Sources.m and GTLNetworking_Sources.m in my project, it shows an error saying “This file needs to be compiled with ARC disabled.” upon building the project. Can you please tell me the possible solution and the reason why this is happening. Thank you.

  33. zennia says:

    Hi Nirbhay. Your code works fine for iOS 8 as well. But I would like to contribute a tiny correction in the – (void)authenticate method.

    It should be like this:

    – (void)authenticate {
    //Get auth object from keychain if available
    [self storedAuth];

    //Check if auth was valid
    if (![self isAuthValid])
    NSLog(@”User not authenticated”);
    if ([self hasViewController])
    [self showOAuthSignInView];

    Otherwise, the application authenticates successfully for the first time, but after that every time it doesn’t authenticate at all.


  34. Riduan says:

    Hi Nirbhay,
    I have followed the instruction as the way you mentioned but when i build i get an error ‘ ‘Lexical Or Preprocessor Issue ‘GTLDefines.h’ file not found ‘.
    Can you please tell me how can i solve this problem?

  35. Friends, I have very day same problem.

    Please any idea.

    YouTubeHelper: User not authenticated yet.

  36. Hi Nirbhay,

    I ran your code and it worked perfectly.
    However, I’m facing a problem when trying to add it to my project.
    After the class YouTubeHelper call showAuthenticationViewController:

    – (void)showAuthenticationViewController:(UIViewController *)authView {
    [self.navigationController presentViewController:authView animated:NO completion:nil];

    Inside GTMOAuth2ViewControllerTouch.m I’m getting an exc_bad_access, inside loadView, on [super loadView], as below:

    – (void)loadView {
    NSString *nibPath = nil;
    NSBundle *nibBundle = [self nibBundle];
    if (nibBundle == nil) {
    nibBundle = [NSBundle mainBundle];
    NSString *nibName = self.nibName;
    if (nibName != nil) {
    nibPath = [nibBundle pathForResource:nibName ofType:@”nib”];
    if (nibPath != nil && [[NSFileManager defaultManager] fileExistsAtPath:nibPath]) {
    [super loadView]; <<<< exc_bad_access here!
    } else {
    // One of the requirements of loadView is that a valid view object is set to
    // self.view upon completion. Otherwise, subclasses that attempt to
    // access self.view after calling [super loadView] will enter an infinite
    // loop due to the fact that UIViewController's -view accessor calls
    // loadView when self.view is nil.
    self.view = [[[UIView alloc] init] autorelease];

    #if DEBUG
    NSLog(@"missing %@.nib", nibName);

    Any idea why this is happening?


  37. DIvyesh Savaliya says:

    Hi Nirbhay,
    When i click “Allow” in permission it gives me following error in console.

    Error Error Code=401 “(null)”
    Error data:
    error = “invalid_client”;

    Please help me.
    What i am doing wrong?

  38. htad says:

    Can I login with hardcode user/pass ?

  39. danielrosero says:

    Anyone got this working IOS9?

  40. prosopikes sxeseis says:

    Thnk you for some other informative blog. Whee else could I gget that kind of info weitten in such an ideal means?
    I have a projeect that I’m simply now working on, and I have been at the look
    out for such information.

  41. What’s Happening i am new to this, I stumbled upon this I have discovered It positively helpful and it has aided me out loads.

    I’m hoping to give a contribution & assist different users like its helped me.
    Great job.

  42. astrologie says:

    Wonderful goods from you, man. I’ve understand your stuyff previous
    to and yoou aare justt extremely fantastic. I really like what you’ve acquired here,
    certainly like wnat you are stating and the way in whih you say it.
    Youu make it enjoyable and you still caare for to keep it sensible.
    I can not wait to read far more rom you.
    This is really a tremendous site.

  43. tarot says:

    I’m very pleased to uncover this great site. I need to to thank you for ones time for this fantastic read!!
    I defnitely savored every bit of it and I have you bookmarked to see new things in your site.

  44. There is definately a great deal to learn about this subject.
    I like all of the points you made.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: