add youtube api

This commit is contained in:
Ruling-Mac 2015-10-21 14:39:30 +08:00
parent cbd05eadc7
commit b6c831714a
5 changed files with 44 additions and 2 deletions

View File

@ -30,6 +30,14 @@ class Admin::VideoChannelsController < OrbitAdminController
end
end
def show
@video_channel = VideoChannel.find(params[:id])
channel_id = @video_channel.channel_link.split("/")[-1]
uri = URI('https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=' + channel_id + '&key=AIzaSyCTFdyLgb7GJfrr1JOI3gvVslZFw7td2zQ')
@r = Net::HTTP.get(uri) # => String
@r = JSON.parse(@r)
end
def update
video_channel = VideoChannel.find(params[:id])

View File

@ -1,3 +1,25 @@
class VideoChannelsController < ApplicationController
def index
end
def show
@video_channel = VideoChannel.find(params[:id])
channel_id = @video_channel.channel_link.split("/")[-1]
uri = URI('https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=' + channel_id + '&key=AIzaSyCTFdyLgb7GJfrr1JOI3gvVslZFw7td2zQ')
result = Net::HTTP.get(uri) # => String
result = JSON.parse(result)
nextPageToken = result['nextPageToken']
videos = {}
while !nextPageToken.nil?
result['items'].each do item
video = item['snippet']
end
end
end
end

View File

@ -14,7 +14,7 @@
<% @video_channels.each do |video_channel| %>
<tr>
<td>
<a href="/admin/video_channels" target="_blank"><%= video_channel.title %></a>
<a href="/admin/video_channels/<%= video_channel.id.to_s %>" target="_blank"><%= video_channel.title %></a>
<div class="quick-edit">
<ul class="nav nav-pills">
<% if can_edit_or_delete?(video_channel) %>

View File

@ -0,0 +1,10 @@
<%= @video_channel.channel_link %>
<br>
<br>
Video Title: <%= @r['items'].first['snippet']['title'] %><br>
Description: <%= @r['items'].first['snippet']['description'] %><br>
Publish Date: <%= @r['items'].first['snippet']['publishedAt'] %><br>
img1: <img src="<%= @r['items'].first['snippet']['thumbnails']['default']['url'] %>"><br>
img2: <img src="<%= @r['items'].first['snippet']['thumbnails']['medium']['url'] %>"><br>
img3: <img src="<%= @r['items'].first['snippet']['thumbnails']['high']['url'] %>"><br>
Channel Title: <%= @r['items'].first['snippet']['channelTitle'] %><br>

View File

@ -1 +1,3 @@
sadsadaskldasjdlkasdkla
aaaaaa
<%= render_view %>