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

Improve Documentation on OAuth2 usage #97

Closed amitamb closed 12 years ago

amitamb commented 12 years ago

I am new to OAuth & OAuth2. It looks like from looking at pull request and doumentation youtube_it supports OAuth2 but I could not find a good documentation for it.

Following pull request was helpful

https://github.com/kylejginavan/youtube_it/pull/46/files

By going the OAuth2 documentation

https://github.com/intridea/oauth2

I creating following actions to test OAuth2 support

  def get_access
    client = YouTubeIt::OAuth2Client.new(:client_id => 'client_id', :client_secret => 'client_secret')
    redirect_to client.oauth_client.auth_code.authorize_url(:redirect_uri => 'http://localhost:3000/oauth2callback', :scope => "https://gdata.youtube.com")
  end

  def oauth2callback
    client = YouTubeIt::OAuth2Client.new(:client_id => 'client_id', :client_secret => 'client_secret')
    @token = client.oauth_client.auth_code.get_token(params[:code], :redirect_uri => 'http://localhost:3000/oauth2callback', :headers => {'Authorization' => 'Basic authorization_code', :grant_type => "authorization_code"})
    #render :text => @token.token
    client = YouTubeIt::OAuth2Client.new(:client_access_token => @token.token, :client_refresh_token => @token.refresh_token, :client_id => 'client_id', :client_secret => 'client_secret', :dev_key => dev_key")
    @result = client.profile #videos_by({ :query => "lol", :page => 1, :per_page => 10 })
    render :text => @result.inspect
  end

There are two problems here

Current version is giving OAuth2 Error at client.profile call. Other thing is when I inspect returned token (i.e. @token) it does not have resresh_token. Furthermore following documentation suggests that we should pass grant_type parameter in token request

https://developers.google.com/youtube/2.0/developers_guide_protocol_oauth2#OAuth2_Server_Side_Web_Applications_Flow

But I could not set it as parameter in token request call.

Could someone shed light on how to use it. If possible also update documentation to make it more clear on usage otherwise I will send pull request once I understand it.

chebyte commented 12 years ago

hi there all documentation is in the youtube api , for oauth2 you can go here

https://developers.google.com/youtube/2.0/developers_guide_protocol_oauth2

but I made into the wiki a how to for use oauth 2 with our gem, you can see it here

I hope that this help

https://github.com/kylejginavan/youtube_it/wiki/How-To:-Use-OAuth-2