Swiftpack.co -  Enchan1207/YoutubeKit as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
Enchan1207/YoutubeKit
API framework of Youtube Data API (v3).
.package(url: "https://github.com/Enchan1207/YoutubeKit.git", from: "v2.5.0")

YoutubeKit

SPM platforms release

Overview

Swift framework for Youtube Data API (v3).

Installation

Now, This framework only supports SPM (Swift Package Manager).

Usage

NOTE: Before you read, please create project and generate API credentials on Google Cloud Platform.

Instantiation

If you don't have any access tokens:

// Credentials
let API_KEY = "XXXXXX"
let CLIENT_ID = "XXXXXX"
let CLIENT_SECRET = "XXXXXX"

// instantiation 
let API_CREDENTIAL = YoutubeKit.APICredential(apikey: API_KEY, clientID: CLIENT_ID, clientSecret: CLIENT_SECRET)

let youtube = YoutubeKit(apiCredential: API_CREDENTIAL, accessCredential: nil)

or if you already have access token:

// Credentials
let API_KEY = "XXXXXX"
let CLIENT_ID = "XXXXXX"
let CLIENT_SECRET = "XXXXXX"
let ACCESS_TOKEN = "XXXXXX"
let REFRESH_TOKEN = "XXXXXX"

// instantiation 
let API_CREDENTIAL = YoutubeKit.APICredential(apikey: API_KEY, clientID: CLIENT_ID, clientSecret: CLIENT_SECRET)
let ACCESS_CREDENTIAL = YoutubeKit.AccessCredential(accessToken: ACCESS_TOKEN, refreshToken: REFRESH_TOKEN, expires: Date(), grantedScopes: [.readwrite])

let youtube = YoutubeKit(apiCredential: API_CREDENTIAL, accessCredential: ACCESS_CREDENTIAL)

Authorize

To authorize to access user datas in your application, set Scope and call authorize.
(in details about scope, see here).

NOTE: This authorization flow can be only used at iOS or macOS. if you want to use it at console application, you need to set AccessCredential when instantiation.

for iOS:

let scope: [YoutubeKit.Scope] = [.readwrite, .forceSSL]
self.youtube.authorize(presentViewController: self, scope: scope) { (credential) in
    print(credential)
} failure: { (error) in
    print(error)
}

for macOS:

let scope: [YoutubeKit.Scope] = [.readwrite, .forceSSL]
self.youtube.authorize(scope: scope) { (credential) in
    print(credential)
} failure: { (error) in
    print(error)
}

Call API endpoints

Example: search

let query = "HIKAKIN"
self.youtube.search(query: query, maxResults: 1) { (result) in
    for item in result.items{
        print(item.serialize()!)
    }
} failure: { (_error) in
    print(error)
}

Response:

{
    "id": {
        "kind": "youtube#channel",
        "channelId": "UCZf__ehlCEBPop-_sldpBUQ"
    },
    "snippet": {
        "thumbnails": {
            "default": {
                "url": "https:\/\/yt3.ggpht.com\/ytc\/AAUvwniFFE8I4vqAWJY-iQltV1kvYhtD-iM0wgsS6nv9lA=s88-c-k-c0xffffffff-no-rj-mo"
            },
            "high": {
                "url": "https:\/\/yt3.ggpht.com\/ytc\/AAUvwniFFE8I4vqAWJY-iQltV1kvYhtD-iM0wgsS6nv9lA=s800-c-k-c0xffffffff-no-rj-mo"
            },
            "medium": {
                "url": "https:\/\/yt3.ggpht.com\/ytc\/AAUvwniFFE8I4vqAWJY-iQltV1kvYhtD-iM0wgsS6nv9lA=s240-c-k-c0xffffffff-no-rj-mo"
            }
        },
        "channelTitle": "HikakinTV",
        "title": "HikakinTV",
        "description": "HikakinTVはヒカキンが日常の面白いものを紹介するチャンネルです。 ◇プロフィール◇ YouTubeにてHIKAKIN、HikakinTV、HikakinGames、HikakinBlogと 4つの ...",
        "channelId": "UCZf__ehlCEBPop-_sldpBUQ",
        "publishedAt": "2011-07-19T11:31:43Z"
    }
}

Dependencies

Due to the update timing, it is possible that everything has not been listed here. See Package.swift for the exact dependencies.

GitHub

link
Stars: 1
Last commit: 3 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

3 weeks ago

Changes

  • XXXCredential系のプロパティを(getterのみ)publicに変更

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API