Setting up YouTube access within app, stuck on retrieving url response

395 Views Asked by At

I can't find any answers or similar questions to my YouTube API puzzle and hoping someone can help.

My iOS app, which makes a video within it, needs to connect to a user's YouTube account so they can upload the video for others to see etc.

I've followed the API documentation and managed to connect to the authentication part where the user logs into their account, (code I used posted below).

It works in the sense it takes user to the login page for Google, when logged in the page asks if the user would like to authorise the app access to account, etc. When the user accepts though, I understand there should be data returned which gives the app authentication, the token code, so it can be used to upload videos later within the app.

My question is.... How do I retrieve this data? When I click accept it simply takes me to another webpage, but I don't know where to retrieve the info.

Thanks in advance for anyone who can point me in the right direction.

#define kAuthUrl @"https://accounts.google.com/o/oauth2/auth?"
#define kClientID @"client_id=xxxxxxxxxxxMyUniqueIDDetailsxxxxxxxxxx&" 
#define kRediretUri @"redirect_uri=urn:ietf:wg:oauth:2.0:oob&"
#define kScopeUL @"scope=https://www.googleapis.com/auth/youtube.upload&"
#define kResponse @"response_type=code"

Above code placed in header file.

- (void)viewDidLoad

{

NSString *loginURL = [NSString stringWithFormat:@"%@%@%@%@%@", kAuthUrl, kClientID, kRediretUri, kScopeUL, kResponse]; 

NSURLRequest * urlReq = [NSURLRequest requestWithURL: [NSURL URLWithString:loginURL]];

[_webView loadRequest:urlReq];

[super viewDidLoad];
// Do any additional setup after loading the view.

}

From the YouTube API documentation it says

When this value is used, your application can sense that the page has loaded and the title of the HTML page contains the authorization code. It is then up to your application to close the browser window if you want to ensure that the user never sees the page that contains the authorization code. The mechanism for doing this varies from platform to platform.

Where "this value" refers to the redirect_uri I chose, as opposed to a local host redirect.

How can I sense the user has logged on to their account and pressed the "accept" button, and this now also leads me on to asking how to know this and then retrieve the code from the returned url while closing the browser.

Cheers, Jim.

1

There are 1 best solutions below

2
On

My strong recommendation is to use the Google Toolbox for Mac OAuth 2 Controllers project to handle all the details of your OAuth 2 integration for you.