Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle task API authentication issue ruby
    text
    copied!<p>I am having the problem to authenticate a user for google tasks.</p> <p>At first it authenticates the user and do things perfect. But in the second trip it throws an error.</p> <pre><code>Signet::AuthorizationError - Authorization failed. Server message: { "error" : "invalid_grant" }: </code></pre> <p>following is the code:</p> <pre><code>def api_client code="" @client ||= (begin client = Google::APIClient.new client.authorization.client_id = settings.credentials["client_id"] client.authorization.client_secret = settings.credentials["client_secret"] client.authorization.scope = settings.credentials["scope"] client.authorization.access_token = "" #settings.credentials["access_token"] client.authorization.redirect_uri = to('/callbackfunction') client.authorization.code = code client end) end get '/callbackfunction' do code = params[:code] c = api_client code c.authorization.fetch_access_token! result = c.execute("tasks.tasklists.list",{"UserId"=&gt;"me"}) unless result.response.status == 401 p "#{JSON.parse(result.body)}" else redirect ("/oauth2authorize") end end get '/oauth2authorize' do redirect api_client.authorization.authorization_uri.to_s, 303 end </code></pre> <p>What is the problem in performing the second request?</p> <p>UPDATE: This is the link and parameters to user consent.</p> <pre><code>https://accounts.google.com/o/oauth2/auth? access_type=offline&amp; approval_prompt=force&amp; client_id=somevalue&amp; redirect_uri=http://localhost:4567/oauth2callback&amp; response_type=code&amp; scope=https://www.googleapis.com/auth/tasks </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload