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

refresh_access_token! returns invalid_client #183

Closed ngw closed 10 years ago

ngw commented 11 years ago

Hi, I'm using youtube_it to interact with the youtube API to basically fetch comments and manage some channels using the Oauth2 client. I managed to obtain a valid token using omniauth-youtube, and I have been able to query youtube and get the data I want. Right now I have an access_token, a refresh_token, a dev_key, and pretty much everything needed as specified in the documentation. My problem is that I can't apparently refresh my token once it expires, and I get a response that apparently is not managed by the gem:

client = YouTubeIt::OAuth2Client.new( client_access_token: access_token, client_refresh_token: refresh_token, client_token_expires_at: u.identities.last.expires_at, dev_key: dev_key, client_secret: dev_key, client_id: 'engagement-console' )
client.refresh_access_token!
OAuth2::Error: invalid_client:
{
  "error" : "invalid_client"
}
from /Users/ngw/.rvm/gems/ruby-1.9.3-p448@conversation_flow_v2_0/gems/oauth2-0.8.1/lib/oauth2/client.rb:108:in `request'
from /Users/ngw/.rvm/gems/ruby-1.9.3-p448@conversation_flow_v2_0/gems/oauth2-0.8.1/lib/oauth2/client.rb:131:in `get_token'
from /Users/ngw/.rvm/gems/ruby-1.9.3-p448@conversation_flow_v2_0/gems/oauth2-0.8.1/lib/oauth2/access_token.rb:86:in `refresh!'
from /Users/ngw/.rvm/gems/ruby-1.9.3-p448@conversation_flow_v2_0/gems/youtube_it-2.1.13/lib/youtube_it/client.rb:485:in `refresh_access_token!'
from (irb):30
from /Users/ngw/.rvm/gems/ruby-1.9.3-p448@conversation_flow_v2_0/gems/railties-3.2.13/lib/rails/commands/console.rb:47:in `start'
from /Users/ngw/.rvm/gems/ruby-1.9.3-p448@conversation_flow_v2_0/gems/railties-3.2.13/lib/rails/commands/console.rb:8:in `start'
from /Users/ngw/.rvm/gems/ruby-1.9.3-p448@conversation_flow_v2_0/gems/railties-3.2.13/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

How can I solve this problem? I'm doing everything in the console right now so it's honestly not entirely clear how to build the app: should I save in the DB the new refresh_token once I've been able to get it?

jgkite commented 11 years ago

I had this problem as well, and it was my mistake. I was using the incorrect client_id and it looks like you are as well. Your client_id is your app's OAuth Consumer Key ([SOMETHING_LONG_HERE].apps.googleusercontent.com). I'm not sure what 'engagement_console' means to your app, but it's not your OAuth Consumer Key.