kylejginavan / youtube_it

An object-oriented Ruby wrapper for the YouTube GData API
http://groups.google.com/group/ruby-youtube-library
595 stars 223 forks source link

OAuth request being treated as AuthSub #24

Closed rcaught closed 13 years ago

rcaught commented 13 years ago

I have generated an access token and secret, but when I try to grab any user information I get the following error:

a = YouTubeIt::OAuthClient.new(:consumer_key => 'consumer_key', :consumer_secret => 'consumer_secret', :dev_key => 'dev_key', :debug => true)
a.authorize_from_access('token', 'secret')
a.current_user
=> NoMethodError: undefined method `elements' for nil:NilClass

When I look at the body of the GET, it looks like the request is being treated as AuthSub.

a.access_token.get("http://gdata.youtube.com/feeds/api/users/default").body
=> "<HTML>\n<HEAD>\n<TITLE>Token invalid - Invalid AuthSub token.</TITLE>\n</HEAD>\n<BODY BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\">\n<H1>Token invalid - Invalid AuthSub token.</H1>\n<H2>Error 401</H2>\n</BODY>\n</HTML>\n"

Any thoughts?

kylejginavan commented 13 years ago

We just did a complete re-write on the gem for the 2.0 release that included an OAuth middleware. My thought is that I might have missed something :)

Give me 24hrs to fix.

Thanks for logging an issue.

kylejginavan commented 13 years ago

Double check your token please. Google throws the same error for invalid AuthSub or OAuth tokens. In addition, this is an old error message. I would advise upgrading to the latest version of this gem. I have just confirmed this is working as expected.

Thanks, Kyle

kylejginavan commented 13 years ago

Here is a gist that will help you generate a valid token from console.

https://gist.github.com/1069420

Let me know if you have further trouble.

huertanix commented 13 years ago

I'm using the 2.0 release and seem to be having the same issue; This gist doesn't specify whether the key that needs to be used is the developer API key or the OAuth Consumer Key that Google provides in their Manage Domains page . I've tried both and neither works.

chebyte commented 13 years ago

hi, you problem is that your token is wrong

this is the way to get an oauth token manually

first you have to run

require 'rubygems'
require 'oauth'

KEY     = "CONSUMER KEY"
SECRET  = "CONSUMER SECRET"

consumer = OAuth::Consumer.new(KEY, SECRET, {
  :site=>"https://www.google.com", 
  :request_token_path=>"/accounts/OAuthGetRequestToken",
  :authorize_path=>"/accounts/OAuthAuthorizeToken",
  :access_token_path=>"/accounts/OAuthGetAccessToken"})

request_token = consumer.get_request_token(
  {:oauth_callback => "YOUR URL SITE" },
  {:scope => "http://gdata.youtube.com"})

puts request_token.token          # The request token itself
puts request_token.secret         # The request tokens' secret
puts request_token.authorize_url  # The authorization URL at Google

then you have to go with your browser to the url that return this "request_token.authorize_url" after that you did click on "Allow Access" on youtube, this going to redirect you to url like this

http://www.yoursite.com?oauth_verifier=Rp3gNaimhHj4LC3IW_aUyyl1&oauth_token=1%2FHaMOv_KirssRfl8PxSQ2tb-LPuyvXv8P_avQBI-SSX8

so them run this script


require 'rubygems'
require 'oauth'

KEY     = "CONSUMER KEY"
SECRET  = "CONSUMER SECRET"

consumer = OAuth::Consumer.new(KEY, SECRET, {
  :site=>"https://www.google.com", 
  :request_token_path=>"/accounts/OAuthGetRequestToken",
  :authorize_path=>"/accounts/OAuthAuthorizeToken",
  :access_token_path=>"/accounts/OAuthGetAccessToken"})

request_token = consumer.get_request_token(
  {:oauth_callback => "YOUR URL SITE" },
  {:scope => "http://gdata.youtube.com"})

#Recreate the (now authorized) request token
   token = OAuth::RequestToken.new(consumer, 
                                 'HERE put request token that return the first script',
                                 'HERE put request token secret that return the first script')
  # Swap the authorized request token for an access token                                        
  @atoken = token.get_access_token(
                    {:oauth_verifier => 'here put oauth_verifier that return browser callback, you can see it in the url' })

  @access_token = OAuth::AccessToken.new(consumer, @atoken.token, @atoken.secret)                

  puts @atoken.token
  puts @atoken.secret

now you are ready for use youtube_it gem with your oauth token, you can run this script with youtube_it

require 'rubygems'
require 'youtube_it'

KEY     = "YOUR CONSUMER KEY"
SECRET  = "YOUR CONSUMER SECRET"

client = YouTubeIt::OAuthClient.new(:consumer_key => KEY, :consumer_secret => SECRET, :dev_key => "your dev key")
client.authorize_from_access("HERE put the token that return the second script","HERE put the token secret that return the second script")

puts client.current_user

and this is all!, you can see an example how you can do it with rails here http://runerb.com/2010/01/12/ruby-oauth-youtube/

Best, mauro