0

I want to access the contacts of authenticated user . I have got the refresh and access token from oauth playground. How do I use these tokens to call people's api?

3
  • Do you have the client id and the client secret? Commented Sep 4, 2020 at 9:48
  • StackOverflow works best when you can show specific code that you are using, or a specific problem that you have been trying to solve, but that you need help in debugging the problem. Open-ended questions such as these are much more difficult. If you can show us what you've tried so far, or what,specifically, you're having problems with, we have a better chance of helping you. See How do I ask a good question? Commented Sep 4, 2020 at 10:00
  • Yes i do have a client id and secret @ziganotschka Commented Sep 4, 2020 at 19:37

1 Answer 1

2

In your case probably the easiest is to create an authentification flow as per documentation, whereby you hardcode the token.json file yourself.

  • If you run the sample code from the quickstart without having a token.json file, you will be redirected to an authorization URL where you have to authenticate with your account, so that a token file with your credentials will be created.
  • However, if you already have a token file for a user, you do not need to authorize the app by signing in as the given user.
  • The structure of a token.json file is the following:
{"access_token":"XXXXXXXXXXXXXXX","refresh_token":"YYYYYYYYYY","scope":"https://www.googleapis.com/auth/ZZZZZZZZZ","token_type":"Bearer","expiry_date":UNIX TIMESTAMP IN SECONDS}
  • If you possess the required information nothing stops you from creating a token.json file yourself

Alternatively

oauth2Client.setCredentials({
  refresh_token: 'STORED_REFRESH_TOKEN'
});

to assign to the oauth2Client a refresh token manually.

Sign up to request clarification or add additional context in comments.

2 Comments

I have followed the documentation to create an authentication flow, after authorizing the app , when i enter the code, I get the following error: { error: 'invalid_grant', error_description: 'Malformed auth code.' }
Have you decoded the token? See here. There can be also other problems, e.g. user did not grant you offline access or revoked access, have a look at the possible scenarios.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.