Anand
Anand

Reputation: 121

Accessing Google Api using Nodejs

I have scaffolded a web app which is able to register a user with Passportjs and Google Oauth2. While registering the user in the scopes I am asking for accessing the Google Plus API and retrieving the accessToken and refreshToken to be persisted in the MongoDB.

Later in the application I am trying to make an API call to retrieve Google Plus user profile to test . I am following the following steps in the code

var oAuth2 = googleCredentials.oauthClient(); // Setting a new Oauth2 // Client using Project credentials

then retrieving the access_token and refresh_token for this particular user and setting the credentials like below

oAuth2.setCredentials({
      access_tokens: user[0].access_token,
      refresh_tokens: user[0].refresh_token
    });

then making an API call

  plus.people.get({
      userId: 'me',
      auth: oAuth2
    }, function (err, response) {

      console.log(err);
      res.send(response);

    });

but my application errors logging the following error

[Error: No access or refresh token is set.]

Any help would be much appreciated

Upvotes: 0

Views: 715

Answers (1)

Anand
Anand

Reputation: 121

Apologise for people who have spent time reading my code as it was such as obvious bummer . when setting the credentials I was passing plural words such as access_tokens instead of access_token and refresh_token. I spend an entire night trying to figure out the issue.

I am glad that I am able to proceed further.

Upvotes: 1

Related Questions