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?ziganotschka– ziganotschka2020-09-04 09:48:52 +00:00Commented 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?Prisoner– Prisoner2020-09-04 10:00:26 +00:00Commented Sep 4, 2020 at 10:00
-
Yes i do have a client id and secret @ziganotschkaLaxmi Anusri Patti– Laxmi Anusri Patti2020-09-04 19:37:43 +00:00Commented Sep 4, 2020 at 19:37
Add a comment
|
1 Answer
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.jsonfile, 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.jsonfile 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.jsonfile yourself
Alternatively
- Create an
oauth2Clientas described in the documentation for Authentication and authorization with OAuth2 and use the method
oauth2Client.setCredentials({
refresh_token: 'STORED_REFRESH_TOKEN'
});
to assign to the oauth2Client a refresh token manually.
2 Comments
Laxmi Anusri Patti
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.' }
ziganotschka
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.