I'm trying to figure out how to use the new YouTube API (Version 3) in my iOS app but I don't know how to do it. I did many research about it but what I found is all examples and codes for older API so they are not valid. Til now I did understand that for using the new API you have to create a Project in Google Developer Console (and I did it)... but then they send you to a page with some code on it but I really don't understand how to use it. link to google api page What I need to know is how to retrieve some informations from a given URL of a YouTube video, the informations I need are total number of "likes" and total number of "views"... with API 2 it was very simple to do it... but now I really don't know where to begin... Is there someone that please can explain how to achieve this with maybe some examples and some code? I'm pretty sure that a lot of people will benefit from this.
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- Using if let syntax in switch statement
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- Enum with associated value conforming to CaseItera
// Swift 3
Its pretty simple to use. You can use it from javascript, there is a simple module in npmjs: https://www.npmjs.com/package/youtube-api-es6
And, its reference I found on its web: https://www.gyanblog.com/gyan/44-youtube-api-nodejs-usage-example
You don't have to use the iOS client Google provides to make those kinds of request.
Navigate to the API Console and generate a new Simple API Access key for your iOS application. Be sure to enter your app's bundle identifier in the provided window. Alternatively, you can create a Server API key for testing with basic requests and curl from the command line.
Find the relevant endpoint for your needs. To find information about a video, you'll want to use the Videos.list method.
First, set up you URL. I will be using this URL as an example: https://www.youtube.com/watch?v=AKiiekaEHhI
You're going to want to specify a value for the
part
parameter. From your question, it looks like you're going to want to pass in thesnippet
,contentDetails
, andstatistics
values (although for likes and views, you really only need thestatistics
value).Then pass in the
id
of your video (in this caseAKiiekaEHhI
, you can add up to 50 comma-separated IDs) and your API key. Your URL should look something like this :You can also do this in the API Explorer.
Swift implementation:
Objective-C implementation:
(This post has been edited to support
NSURLSession
. For an implementation that usesNSURLConnection
, check the edit history)Your log will look something like this:
The object for the
items
key will be an array of info for each video id you passed in to the request.By digging into this response, you will be able to get the information you need. For example:
Will give you a dictionary of the video's statistics (where you can get the number of likes and the number of views).
This same approach can be used with live events.