0
YouTube APIを使用してYouTubeチャンネルのアプリを作成しています。私はこれを行うことによってAlamofireを使用してプレイリストから動画を取得しています:YouTube動画の視聴を取得するYouTube API
let parameters = ["part":"snippet","maxResults":50,"channelId":CHANNEL_ID,"playlistId":UPLOADS_PLAYLIST_ID,"key":API_KEY] as [String : Any]
class VideoModel: NSObject {
var videoArray = [Video]()
func getFeedVideo() {
Alamofire.request("https://www.googleapis.com/youtube/v3/playlistItems", parameters: parameters, encoding: URLEncoding.default, headers: nil).responseJSON { (response) in
if let JSON = response.result.value {
if let dictionary = JSON as? [String: Any] {
var arrayOfVideos = [Video]()
guard let items = dictionary["items"] as? NSArray else { return }
for items in dictionary["items"] as! NSArray {
print(items)
// Create video objects off of the JSON response
let videoObj = Video()
videoObj.videoID = (items as AnyObject).value(forKeyPath: "snippet.resourceId.videoId") as! String
videoObj.videoTitle = (items as AnyObject).value(forKeyPath: "snippet.title") as! String
videoObj.videoDescription = (items as AnyObject).value(forKeyPath: "snippet.description") as! String
videoObj.videoThumbnailUrl = (items as AnyObject).value(forKeyPath: "snippet.thumbnails.maxres.url") as! String
arrayOfVideos.append(videoObj)
}
self.videoArray = arrayOfVideos
if self.delegate != nil {
self.delegate!.dataReady()
}
}
}
}
}
私の周りに検索してきた、と私はこれを行うための簡単な方法を見つけることができません。私はこのような答えを見つけた:How to get number of video views with YouTube API?しかし、私はスイフトを使用しています。誰にもアイデアはありますか?
可能な重複[YouTubeのAPIを持つビデオビューの数を取得するには?](https://stackoverflow.com/questions/3331176/how-to-get-number-of-video-views-with -youtube-api) – PressingOnAlways
@Jacob:どうしたの?あなたはデータを受け取っているかどうか?ビデオカウントを取得しますか?あなたはそれをYoutube Video Playerに添付するためにビデオIDを取得しますか? – nathan
可能な複製https://stackoverflow.com/questions/3331176/how-to-get-number-of-video-views-with-youtube-api – noogui