Skip to content

Instantly share code, notes, and snippets.

@alanzhao
Created September 27, 2012 00:50
Show Gist options
  • Save alanzhao/3791526 to your computer and use it in GitHub Desktop.
Save alanzhao/3791526 to your computer and use it in GitHub Desktop.
Subscription service
require 'sinatra'
require 'youtube_it'
get '/ytsubscription' do
channels = params[:channels].split(',')
callback = params[:callback]
username = session[:username] # e.g. [email protected]
oauth_type = session[:oauth_type] # e.g. google_oauth2
account = get_cassandra_row(username, oauth_type)
access_token = account['access_token']
refresh_token = account['refresh_token']
expiration = account['valid_thru']
client = YouTubeIt::OAuth2Client.new(
client_access_token: access_token,
client_refresh_token: refresh_token,
client_id: "client_id",
client_secret: "client_secret",
dev_key: "dev_key",
expires_at: expiration
)
begin
channels.each do |channel|
client.subscribe_channel(channel)
end
rescue Exception => ex
raise 'Autentication failed.'
end
redirect_to callback
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment