Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access google connections using google people API

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: '/'
    }));
like image 417
Parth Vyas Avatar asked Mar 03 '17 19:03

Parth Vyas


People also ask

How do I access my Google Contacts API?

To access personal contacts: https://www.googleapis.com/auth/contacts. To access directory information: https://www.googleapis.com/auth/directory.readonly.

What is Google's People API?

The People API lets you: Read and manage the authenticated user's Contacts. Read and copy the authenticated user's "Other contacts" Read profile information for authenticated users and their contacts. Read domain profiles and contacts.

Is Google People API free?

All use of Legacy People API is free of charge. Was this helpful?


1 Answers

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"
  }
}
like image 88
DaImTo Avatar answered Oct 17 '22 20:10

DaImTo