10

I would like to fetch all the google private connections of a user signed in from my app. I've enabled the Google People and the Google Plus API's. I set up the credentials API key, client id & client secret. The url with which I'm trying to fetch the users connections is

https://people.googleapis.com/v1/people/me/connections?fields=connections&key=api_key&access_token=access_token

Also, I'm using the library passport-google-oauth, to get the users access_token. Is there anything that I'm missing in the above URL.

My google auth code is

    // send to google to do the authentication
    // profile gets us their basic information including their name
    // email gets their emails
    app.get('/auth/google', passport.authenticate('google', {
        scope: ['profile', 'email','https://www.googleapis.com/auth/contacts.readonly', 'https://www.googleapis.com/auth/contacts']
    }));

    // the callback after google has authenticated the user
    app.get('/auth/google/callback',
    passport.authenticate('google', {
        successRedirect: '/profile',
        failureRedirect: '/'
    }));
BNK
  • 23,994
  • 8
  • 77
  • 87
Parth Vyas
  • 487
  • 4
  • 16

1 Answers1

2

You have not mentioned what error you are getting but by looking at the url you are using I can tell you a few things.

people.connections.list access private user data. So for one you don't need to add Key that is just used for accessing public data. However having both should not result in any error message.

I have tested the request you are sending and it does work however this request requires that you have authenticated with at least one of the connections scopes.

https://www.googleapis.com/auth/contacts Requests that your app be given read and write access to the contacts in the authenticated user’s Google Contacts. https://www.googleapis.com/auth/contacts.readonly Requests that your app be given read access to the contacts in the authenticated user’s Google Contacts.

If you have not then you will get a no access error message.

{
  "error": {
    "code": 403,
    "message": "Request had insufficient authentication scopes.",
    "status": "PERMISSION_DENIED"
  }
}
Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
  • Okay. I got the API key thing. But with the access_token I pass, I get the following error : **Request is missing required authentication credential. Expected OAuth 2 access token google people api**. I'm using the package google-passport-oauth to get the user token & google-api-nodejs-client to access people API for google – Parth Vyas Mar 16 '17 at 04:32
  • @ParthVyas if you have got the access token, try using it as header of your request (perhaps `Authorization: "Bearer " + accessToken`) – BNK Mar 16 '17 at 06:18
  • 1
    @BNK you don't need to do that by tacking &access_token= on the end of the request you are doing the same thing. – Linda Lawton - DaImTo Mar 16 '17 at 07:39
  • 1
    @ParthVyas please post your auth code I think there is something wrong with your access token generation – Linda Lawton - DaImTo Mar 16 '17 at 07:39
  • 1
    @DaImTo I've updated the question with the auth code, please have a look! – Parth Vyas Mar 16 '17 at 11:35
  • @ParthVyas I have not tried the `passport-google-oauth` library, however according to https://github.com/google/google-api-nodejs-client#retrieve-authorization-code, IMO, you should have the authorization code to get an access token – BNK Mar 17 '17 at 04:03
  • Yes @BNK I'll try the **google-api-nodejs-client** now & check if the token is considered valid or not – Parth Vyas Mar 17 '17 at 05:42
  • @ParthVyas I am not a node dev but where are you adding the client id and client secret? https://c9.io/barberboy/passport-google-oauth2-example – Linda Lawton - DaImTo Mar 17 '17 at 07:59