0
votes

I would like to retrieve birthday and gender from google people API in my backend nodejs server. The access token is generated client side with those 2 scopes: https://www.googleapis.com/auth/user.birthday.read https://www.googleapis.com/auth/userinfo.profile

The client sends the accessToken and the server queries the people API in the following way :

const {google} = require('googleapis');
async function getDataFromPeopleAPI(googleId, accessToken) {
    try {

        let params = {
            resourceName: `people/${googleId}`,
            personFields: 'birthdays,genders',
            access_token: accessToken //generated by client
        };
        let res = await google.people({
            auth: GOOGLE_API_KEY //API key
        }).people.get(params);
        let {birthdays, genders} = res.data;

    } catch (e) {

    }
};

The issue is that even though my birthday is set as public and my gender the people api always returns the same result . I don't receive any error code but I never receive the data I want. Here is the response I get:

  "resourceName": "people/102865456870877320332",
  "etag": "%EgUBBwg3LhoEAQIFBw=="
}

What am I doing wrong when querying the people API ? Thanks !

1
Have you tried using 'people/me' ?Alexandre Cox

1 Answers

0
votes

This might be too old to answer, but here is the correct format of the request:

const {google} = require('googleapis');

let userData = await google
  .people({
    version: "v1", // mention the API version
    auth: process.env.GOOGLE_SERVER_API_KEY,
  })
  .people.get({
    resourceName: "people/me", // not people/${googleId}
    personFields: "genders,birthdays", // mention your scopes
    access_token: accessToken, // generated by client
  });

Refer to this URL for scope documentation: https://developers.google.com/people/api/rest/v1/people/get