abronte / BigQuery

A BigQuery wrapper
86 stars 57 forks source link

basic example fails with "Required parameter is missing: grant_type" #21

Open aep opened 9 years ago

aep commented 9 years ago

the very first example code in the readme fails for me with:

/home/aep/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/signet-    0.6.0/lib/signet/oauth_2/client.rb:947:in `fetch_access_token': Authorization failed.  Server message:     (Signet::AuthorizationError)
{
  "error" : "invalid_request",
  "error_description" : "Required parameter is missing: grant_type"
}
    from /home/aep/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/signet-0.6.0/lib/signet/oauth_2/client.rb:964:in `fetch_access_token!'
    from /home/aep/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/bigquery-0.7.0/lib/big_query/client.rb:42:in `refresh_auth'
    from /home/aep/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/bigquery-0.7.0/lib/big_query/client.rb:33:in `initialize'
    from main.rb:13:in `new'
    from main.rb:13:in `<main>'
gambaroff commented 9 years ago

Could you paste the code making a request? There is an error in your request.

trinityXmontoya commented 9 years ago

I was having the same issue and followed the steps exactly as given in the readme. I also checked to make sure that my computer clock was correct and that the secret key is valid and authorized the provided client_id within the scope of the big_query api.

        opts = {}
        opts['client_id']     = ENV["GOOGLE_BQ_CLIENT_ID"]
        opts['service_email'] = ENV["GOOGLE_BQ_SERVICE_EMAIL"]
        opts['key']           = './my-secret-key.p12'
        opts['project_id']    = ENV["GOOGLE_BQ_PROJECT_ID"]
        opts['dataset']       = 'gdelt-bq:full.events'

        bq = BigQuery::Client.new(opts)

When I try the code within the initialize function using another provider as the client, my credentials are accepted and I receive a token.


     @client =  Google::APIClient.new()

      begin
        key = Google::APIClient::KeyUtils.load_from_pkcs12(opts['key'], 'notasecret')
      rescue ArgumentError
        key = Google::APIClient::KeyUtils.load_from_pem(opts['key'], 'notasecret')
      end

      @client.authorization = Signet::OAuth2::Client.new(
           token_credential_uri: 'https://accounts.google.com/o/oauth2/token',
           audience: 'https://accounts.google.com/o/oauth2/token',
           scope: 'https://www.googleapis.com/auth/bigquery',
           issuer: opts['service_email'],
           signing_key: key)

    refresh_auth
    @bq = @client.discovered_api("bigquery", "v2")

    @project_id = opts['project_id']
    @dataset = opts['dataset']

I tried out the google-api-client gem directly and the exact code provided in the initialize function of BigQuery worked. Submitted a PR for updating the gem dependency.