question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: No access, refresh token or API key is set. setCredentials

See original GitHub issue
<your detailed question and code samples go here> // Retrieve tokens via token exchange explained above or set them: oauth2Client.setCredentials({ access_token: 'ACCESS TOKEN HERE', refresh_token: 'REFRESH TOKEN HERE' // Optional, provide an expiry_date (milliseconds since the Unix Epoch) // expiry_date: (new Date()).getTime() + (1000 * 60 * 60 * 24 * 7) });

this used to work, lately when I updated version, it says TypeError: oauth2Client.setCredentials is not a function

somewhere in the issues, it was suggested to switch to oauth2Client.setCredentials = { access_token: process.env[‘ACCESS_TOKEN’], refresh_token: process.env[‘REFRESH_TOKEN’], expiry_date: true };

and now it returns Error: No access, refresh token or API key is set. How to solve this problem?

Thank you in advance!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

19reactions
mike-seekwellcommented, Dec 21, 2017

@piavgh @bantini Here’s what worked for me:

	var oauth2Client = new auth.OAuth2(clientId, clientSecret, redirectUrl);
	oauth2Client.credentials = {
	                refresh_token: 'your_refresh_token'
	};
	oauth2Client.refreshAccessToken(function(err, tokens){
	console.log(tokens)
	oauth2Client.credentials = {access_token : tokens.access_token}
	callback(oauth2Client);
4reactions
opyatecommented, Jul 20, 2018

FWIW, here’s the modified (from this) code I use on Cloud Functions which is limited to Node 6.14.0

const {google} = require('googleapis')
const plus = google.plus('v1')
const oauth2Client = new google.auth.OAuth2('your-client-id', 'secret', 'redirect')
google.options({ auth: oauth2Client })
const fromAuthCode = (authCode, userId) => {
  return oauth2Client.getToken(authCode).then(tokenResponse => {
    oauth2Client.setCredentials(tokenResponse.tokens)
    return plus.people.get({ userId: userId }).then(response => {
      return response
    })
  })
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Google API. No access, refresh token, API key or refresh ...
'Error: No access, refresh token, API key or refresh handler callback is set.' I can not find a solid reference to this, I...
Read more >
Error: No access, refresh token or API key is set – iTecNote
Yes I have downloaded the json, renamed to client_secret.json and added to the application folder. Here is the code: const fs = require('fs');...
Read more >
Google APIs Node.js Client - googleapis documentation
OAuth2 client; Using API keys; Application default credentials ... The user has revoked your app's access; The refresh token has not been used...
Read more >
Implementing Server-Side Authorization | Gmail
This access token is passed to the Gmail API to grant your application access to user data for a ... """Error raised when...
Read more >
google-auth-library - npm
getToken (code); // Make sure to set the credentials on the OAuth2 client. oAuth2Client.setCredentials(r.tokens); console.info('Tokens ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found