Error 400: readMask is required. Please specify one or more valid paths - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Friday, June 16, 2023

Error 400: readMask is required. Please specify one or more valid paths

I'm traying to create a new contact in my google account using GoogleAPIClient library.

My function code's is this:

    public function createContact(Google_Client $client, $nombre, $telefonos, $correo, $biografia)
    {
        $service = new Google_Service_PeopleService($client);

        // Crear una nueva persona y establecer su nombre, número de teléfono y biografía
        $person = new Google_Service_PeopleService_Person();

        $name = new Google_Service_PeopleService_Name();
        $name->setGivenName($nombre);
        $person->setNames([$name]);

        // Crear una lista para almacenar los números de teléfono
        $phoneNumbersList = [];
        foreach ($telefonos as $telefono){
            $phoneNumber = new Google_Service_PeopleService_PhoneNumber();
            $phoneNumber->setValue($telefono);
            // Añadir el número de teléfono a la lista
            $phoneNumbersList[] = $phoneNumber;
        }
        // Establecer los números de teléfono del contacto a la lista que acabamos de crear
        $person->setPhoneNumbers($phoneNumbersList);

        $emailAddress = new Google_Service_PeopleService_EmailAddress();
        $emailAddress->setValue($correo);
        $person->setEmailAddresses([$emailAddress]);

        $biography = new Google_Service_PeopleService_Biography();
        $biography->setValue($biografia);
        $person->setBiographies([$biography]);

        // Crear el contacto
        $createdContact = $service->people->createContact($person, [
            'personFields' => 'names,phoneNumbers,emailAddresses,biographies'
        ]);

        // Obtener el ID del contacto creado
        $contactId = $createdContact->getResourceName();

        return $contactId;
    }

When I execute this function it give me this response:

{
"error": {
"code": 400,
"message": "readMask is required. Please specify one or more valid paths. Valid paths are documented at https://developers.google.com/people/api/rest/v1/people/get.",
"errors": [
{
"message": "readMask is required. Please specify one or more valid paths. Valid paths are documented at https://developers.google.com/people/api/rest/v1/people/get.",
"domain": "global",
"reason": "badRequest"
}
],
"status": "INVALID_ARGUMENT"
}
}

I don't undesrtand why I'm getting this error, I already have a readMask. I also try create contacts using this other executions:

$createdContact = $service->people->createContact($person, [
    'requestMask.includeField' => 'person.metadata,person.names,person.phoneNumbers,person.emailAddresses,person.biographies'
]);

$service->people->createContact($person, ['readMask' => 'names,emailAddresses,phoneNumbers,biographies']);


$service->people->createContact($person, ['personFields' => ['names', 'emailAddresses', 'phoneNumbers', 'biographies']]);

The response given is always the same.

¿Do I need something else? ¿There is something wrong wiht my function?



source https://stackoverflow.com/questions/76484159/error-400-readmask-is-required-please-specify-one-or-more-valid-paths

No comments:

Post a Comment