Skip to content

Instantly share code, notes, and snippets.

@bryckbost
Created January 8, 2009 20:39
Show Gist options
  • Save bryckbost/44869 to your computer and use it in GitHub Desktop.
Save bryckbost/44869 to your computer and use it in GitHub Desktop.
def get_upload_url(meta)
xml_entry = build_xml_entry(meta)
headers = {
'Authorization' => meta[:client_login] ? %Q(GoogleLogin auth="#{meta[:client_login]}") : %Q(AuthSub token="#{meta[:auth_sub]}"),
'X-GData-Client' => YT_CONFIG['auth_sub']['client_key'],
'X-GData-Key' => "key=#{YT_CONFIG['auth_sub']['developer_key']}",
'Content-Length' => xml_entry.length.to_s,
'Content-Type' => "application/atom+xml; charset=UTF-8"
}
response = connection.post('/action/GetUploadToken', xml_entry, headers)
meta[:nexturl] ||= 'http://www.youtube.com/my_videos'
upload = {}
(Hpricot.XML(response.body)/:response).each do |elm|
upload[:url] = "#{(elm/:url).text}?#{{:nexturl => meta[:nexturl]}.to_query}"
upload[:token] = (elm/:token).text
end if response.code == "200"
upload[:code] = response.code
upload
end
# Sends a POST to YouTube to get an authentication token
#
# Google will return a response that contains the authentication
# token needed to execute API operations associated with the user.
def client_login(email, password, source = "Ruby")
url = URI.parse('https://www.google.com/youtube/accounts/ClientLogin')
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = (url.scheme == 'https')
response = http.post(url.path, "Email=#{email}&Passwd=#{password}&service=youtube&source=#{source}", {'Content-Type' => 'application/x-www-form-urlencoded'})
# Auth=AIwbFATNWUoOao3zotg5Z6lCyjEZjKcXzL9ZQSTCi8EIIgMOLk0yk6UYveeeE_3gDozc8nyGaqkWBOIxgK_jkiaVqGHCLLhmB54nV6p3b-R2cfxmika5659FoWE4X3CWKq2APlemhyeVJQzUYRhqtig8TUDgOfaboQ
# YouTubeUser=drmo414
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment