Skip to content

Token for multiple request #81

Description

@anddimario

Hi, i'm creating a batch script that execute requests with async, there are about 20 requests, and on client request i've this error:

Error: No access or refresh token is set.
    at OAuth2Client.request (/home/andrea/projects/toweb/node_modules/googleapis/lib/auth/oauth2client.js:184:11)
    at /home/andrea/projects/toweb/node_modules/googleapis/lib/auth/oauth2client.js:205:16
    at Request._callback (/home/andrea/projects/toweb/node_modules/googleapis/lib/transporters.js:78:21)
    at Request.self.callback (/home/andrea/projects/toweb/node_modules/googleapis/node_modules/request/index.js:148:22)
    at Request.EventEmitter.emit (events.js:98:17)
    at Request.<anonymous> (/home/andrea/projects/toweb/node_modules/googleapis/node_modules/request/index.js:891:14)
    at Request.EventEmitter.emit (events.js:117:20)
    at IncomingMessage.<anonymous> (/home/andrea/projects/toweb/node_modules/googleapis/node_modules/request/index.js:842:12)
    at IncomingMessage.EventEmitter.emit (events.js:117:20)
    at _stream_readable.js:883:14

It's a random error and not on a specific request and i think it's something like a timeout on oauth.
Here's the code for a request:

var request_avgtimeonsite =  client.analytics.data.ga.get({ids: 'ga:' + item.id, 'start-date': start_date, 'end-date': end_date, metrics: "ga:avgtimeonsite"}).withAuthClient(oauth2Client);

Have you some suggestions about this problem?

Thanks for your time.
Best regards

Activity

  1. bentona commented on Aug 24, 2013

    @bentona
    Contributor

    Not the maintainer, but more code might help. The construction of your auth client at least?

  2. anddimario commented on Aug 26, 2013

    @anddimario
    Author

    Hi, yes, sorry, here's the code: https://gist.github.com/anddimario/6338925
    Sometimes it works without problems, i've tried to set a single client and an oauth for each request, but it seems not work.

    Thanks for your time.
    Best regards.

  3. rakyll commented on Aug 26, 2013

    @rakyll
    Contributor

    Is there any chance, this problem is occurring during token refresh? There is a racing condition in this case if there are multiple token refreshing requests are sent out.

  4. anddimario commented on Aug 27, 2013

    @anddimario
    Author

    Hi, i'm looking for use something with async, what do you think it could be the best method to do multiple request?
    I've tried the batch system but there are some problems.

    Thanks for your time.
    Best regards.

  5. rakyll commented on Aug 27, 2013

    @rakyll
    Contributor

    Google implements OData's batch protocol which cant be consumed by the native HTTP implementation of node which leads to implementing and http client in pure JS or implementing a native OData client. Both are not worth the effort, so I'd suggest using async.

    What you can do to avoid your problem, before starting the requests check the expiration date of the token and retrieve a new access token. I'll try to address this in the lib, but temporarily you can solve the problem by making sure your access token is not expired before starting the requests.

  6. anddimario commented on Sep 3, 2013

    @anddimario
    Author

    Hi, i'm usign this link to test my token: https://www.googleapis.com/oauth2/v1/tokeninfo?id_token=
    I saw that tokens aren't expired, but the request gave back errors again and the expire time are not refreshed.
    I've tested the tokens after and they work.
    Could it be some problems with refresh token in oauth method for client?

    Thanks for your time.
    Best regards

  7. rakyll commented on Sep 3, 2013

    @rakyll
    Contributor

    Is it possible for to dump the request bodies and headers so I can try to
    reproduce your problem? My hypothesis about racy token refreshment is
    probably wrong. Even though it's racy, the newly generated access tokens
    don't invalidate the previous ones.

    On Tue, Sep 3, 2013 at 11:03 AM, anddimario [email protected]:

    Hi, i'm usign this link to test my token:
    https://www.googleapis.com/oauth2/v1/tokeninfo?id_token=
    I saw that tokens aren't expired, but the request gave back errors again
    and the expire time are not refreshed.
    I've tested the tokens after and they work.
    Could it be some problems with refresh token in oauth method for client?

    Thanks for your time.
    Best regards

    —
    Reply to this email directly or view it on GitHubhttps://github.com//issues/81#issuecomment-23698595
    .

  8. anddimario commented on Sep 6, 2013

    @anddimario
    Author

    Hi, i've created a function to refresh token function and it seems that the principal problem disappears, but i've the resource limit problem, i'm using sleep too, but it seems that client make all request at the same time.

  9. maxbrodie commented on Dec 28, 2013

    @maxbrodie

    Hi - I recently used apache bench to load test (100 total reqs, 10 at a time) an API endpoint that uses the client to call a Google API. The benchmark only got to request 32 before node threw:

    [Error: No access or refresh token is set.]
    at OAuth2Client.request (/webapp/node_modules/googleapis/lib/auth/oauth2client.js:184:11

    Any info I can contribute to debug this?

  10. ryanseys commented on Jul 31, 2014

    @ryanseys
    Contributor

    Just released 1.0.3 which will likely address this issue. The access token will be refreshed prior to initial request if has expired or is missing and you have a refresh token set. If the request fails due to a missing, invalid, or revoked access token, we will no longer attempt to refresh and re-attempt the request.

    https://github.com/google/google-api-nodejs-client/releases/tag/1.0.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

🚨This issue needs some love.triage meI really want to be triaged.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions