Created
September 27, 2012 00:50
-
-
Save alanzhao/3791526 to your computer and use it in GitHub Desktop.
Subscription service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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