gimite / google-spreadsheet-ruby

Ruby library to read/write Google Spreadsheet
Other
306 stars 52 forks source link

oauth2 error on .files? #43

Closed er1c closed 12 years ago

er1c commented 12 years ago

the session.spreadsheet_by_key will work with my OAuth2 token, but I get an error with session.files

    session = GoogleSpreadsheet.login_with_oauth(@access_token)
    begin
#      @files = session.files
      @ws = session.spreadsheet_by_key("<key>").worksheets[0]

    rescue OAuth2::Error => err
      logger.debug ("OAuth2::Error (#{err.inspect})" )
      raise err
    end
"https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email https://spreadsheets.google.com/feeds"}, @connection=#<Faraday::Connection:0x00000102d55040 @headers={}, @params={}, @options={}, @ssl={}, @parallel_manager=nil, @scheme="https", @host="accounts.google.com", @port=nil, @path_prefix="/o/oauth2/auth", @builder=#<Faraday::Builder:0x000001032f9dc0 @handlers=[Faraday::Request::UrlEncoded, Faraday::Adapter::NetHttp]>, @app=#<Faraday::Request::UrlEncoded:0x000001032f7570 @app=#<Faraday::Adapter::NetHttp:0x000001032f7598 @app=#<Proc:0x000001032f7778@/Users/eric/.rvm/gems/ruby-1.9.3-p0/gems/faraday-0.7.5/lib/faraday/connection.rb:78 (lambda)>>>>>, @token="ya29....", @refresh_token=nil, @expires_in=3600, @expires_at=1335745463, @options={:mode=>:header, :header_format=>"Bearer %s", :param_name=>"bearer_token"}, @params={"token_type"=>"Bearer", "id_token"=>"......."}>
access_token.request get, https://docs.google.com/feeds/default/private/full?v=3, {:header=>{}, :headers=>{"Authorization"=>"Bearer ..."}} and its: header with Bearer %s and ...
OAuth2::Error (#<OAuth2::Error: OAuth2::Error>)
gimite commented 12 years ago

Thanks for the report. I'll take a look.

er1c commented 12 years ago

after I upgraded some oauth libraries I got a better error message

<HTML>
<HEAD>
<TITLE>Token invalid - AuthSub token has wrong scope</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Token invalid - AuthSub token has wrong scope</H1>
<H2>Error 401</H2>
</BODY>
</HTML>

Looks like its an issue on my end but maybe I'm confused on what scope I need to grab

"https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email https://spreadsheets.google.com/feeds"

gimite commented 12 years ago

I haven't tried but here's official document about the required scopes: https://developers.google.com/google-apps/documents-list/?hl=ja#authorizing_requests_with_oauth_20

er1c commented 12 years ago

I updated my scope to below and it works, should probably update the readme:

    :scope:            "https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email https://docs.google.com/feeds https://docs.googleusercontent.com https://spreadsheets.google.com/feeds"
gimite commented 12 years ago

Done.