googleapis / google-api-nodejs-client

Google's officially supported Node.js client library for accessing Google APIs. Support for authorization and authentication with OAuth 2.0, API Keys and JWT (Service Tokens) is included.
https://googleapis.dev/nodejs/googleapis/latest/
Apache License 2.0
11.45k stars 1.92k forks source link

People searchContacts returns an empty object #3277

Open AlessandroAnnini opened 1 year ago

AlessandroAnnini commented 1 year ago

1) Is this a client library issue or a product issue? library issue

2) Did someone already solve this? nope

3) Do you have a support contract? nope

If the support paths suggested above still do not result in a resolution, please provide the following details.

Environment details

Steps to reproduce

import path from 'node:path';
import fs from 'node:fs';
import { authenticate } from '@google-cloud/local-auth';
import { google } from 'googleapis';
import dotenv from 'dotenv';

dotenv.config();

const keyFile = path.join(path.resolve(), './client.oauth2.keys.json');

const people = google.people('v1');

const auth = new google.auth.GoogleAuth({
  keyFile: path.join(path.resolve(), 'chatter-cal-1cfb9a3e830d.json'),
  scopes: ['https://www.googleapis.com/auth/contacts'],
});

google.options({ auth });

export const searchContact = async (phoneNumber) => {
  // https://developers.google.com/people/api/rest/v1/people/searchContacts
  const response = await people.people.searchContacts(
    {
      query: phoneNumber,
      readMask: 'names,phoneNumbers',
      key: process.env.GOOGLE_PEOPLE_API_KEY,
    },
    {
      headers: {
        'X-Goog-Encode-Response-If-Executable': 'base64',
      },
    }
  );

  console.log('\n\nResponse:', JSON.stringify(response, null, 2));
  return response;
};

This is the response:

{
  "config": {
    "url": "https://people.googleapis.com/v1/people:searchContacts?query=<A PHONE NUMBER IN MY CONTACTS>&readMask=names%2CphoneNumbers&key=*****",
    "method": "GET",
    "headers": {
      "X-Goog-Encode-Response-If-Executable": "base64",
      "x-goog-api-client": "gdcl/6.0.4 gl-node/18.12.1 auth/8.8.0",
      "Accept-Encoding": "gzip",
      "User-Agent": "google-api-nodejs-client/6.0.4 (gzip)",
      "Authorization": "Bearer *****",
      "Accept": "application/json"
    },
    "userAgentDirectives": [
      {
        "product": "google-api-nodejs-client",
        "version": "6.0.4",
        "comment": "gzip"
      }
    ],
    "params": {
      "query": <A PHONE NUMBER IN MY CONTACTS>,
      "readMask": "names,phoneNumbers",
      "key": "*****"
    },
    "retry": true,
    "responseType": "json"
  },
  "data": {},  // <---------ALWAYS EMPTY
  "headers": {
    "alt-svc": "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000",
    "cache-control": "private",
    "connection": "close",
    "content-encoding": "gzip",
    "content-type": "application/json; charset=UTF-8",
    "date": "Fri, 07 Jul 2023 07:22:50 GMT",
    "server": "ESF",
    "transfer-encoding": "chunked",
    "vary": "Origin, X-Origin, Referer",
    "x-content-type-options": "nosniff",
    "x-frame-options": "SAMEORIGIN",
    "x-xss-protection": "0"
  },
  "status": 200,
  "statusText": "OK",
  "request": {
    "responseURL": "https://people.googleapis.com/v1/people:searchContacts?query=<A PHONE NUMBER IN MY CONTACTS>&readMask=names%2CphoneNumbers&key=*****"
  }
}

The auth seems fine, the scope is right, the number is absolutely in my contacts and the very same call works when done from this page with the same parameters: People API Reference - Method: people.searchContacts

Am I missing something?

AlessandroAnnini commented 1 year ago

I am sorry, any news about this?

Teddynet commented 1 year ago

Hi to all, any news about this bug? thanks

Teddynet commented 1 year ago

Please let us know if will be fixed, thanks