Coder Social home page Coder Social logo

ios_youtube_browser's Introduction

iOS YouTube Browser Sample

This tutorial explains how to create simple iOS application which working with YouTube API.

First of all, you should create Google account, if you haven’t. Go to Google Developers Console and create the project.

alt tag

In created project, you will have lots of settings, statistics, something else. For your application we need to enable YouTube API.

alt tag

Also you need to create iOS key by this link on the API access tab and Create new iOS key button.

alt tag

alt tag

Now all settings were set up.

We have two question for our simple application. How to receive data from YouTube? And how to play YouTube videos in UIKit?

For receiving the data we will use the next request. Google provides lots of information about API, you can found here. Full information about API, samples, etc.

Sample code for request using AFNetworking:

static NSString * const YouTubeBaseUrl = @"https://www.googleapis.com/youtube/v3/search?part=snippet&q=%@&type=video&videoCaption=closedCaption&key=%@&maxResults=%@";
static NSString * const YouTubeAppKey = @"AIzaSyCs0lcHGW2oW88FO8FeR8j_hXMc9oCG6p0";
static const NSInteger YouTubeMaxResults = 50;

...

NSString *str = [searchString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *url = [NSString stringWithFormat:YouTubeBaseUrl, str, YouTubeAppKey, @(YouTubeMaxResults)];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:url parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
   NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
   NSLog(@"Error: %@", error);
}];

And second question. For this you can use the YouTube Player. It’s great control. And really simple usage:

[self.playerView loadWithVideoId:@"M7lc1UVf-VE"];

I think it doesn’t make sense to explain the details, just download the repository and use the sample ☺

alt tag

That’s all. Happy coding!!!

ios_youtube_browser's People

Contributors

maximbilan avatar

Watchers

James Cloos avatar alelipona avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.