php - I want to register employee information data using the Google API but without having to create custom schemas - Stack Over

I want to register Employee Information data using the Google API but without having to create custom s

I want to register Employee Information data using the Google API but without having to create custom schemas.

With the API and PHP, I managed to create users, but I can't register data in the following fields:

Work Address Employee ID Employee Type Department

I want to populate these fields:

Here is my code:

<?php

`$autoloadPath = ruta del autoload.php
$keyFilePath = ruta del json
        // Verificación de la ruta
        if (!file_exists($autoloadPath)) {
            throw new Exception("No se puede encontrar autoload.php en la ruta: " . $autoloadPath);
        }
        require_once $autoloadPath;

        // Scopes necesarios para la API
        $scopes = [
            ".directory.user",
            ".directory.user.security"
        ];

        // Configuración del cliente de servicio
        $client = new Google_Client();
        $client->setAuthConfig($keyFilePath);
        $client->setScopes($scopes);

        // Delegación en nombre de un superadministrador
        $client->setSubject('superadmin account'); // Reemplaza con el correo del superadmin

        // Obtener el token de acceso
        $token = $client->fetchAccessTokenWithAssertion();
        $accessToken = $token['access_token'];

        $apellidos = 'ALCAZAR ALBA';
        $nombres = 'YA VOY';
        $nombres_apellidos = 'YA VOY ALCAZAR ALBA';
        $email = '[email protected]';
        $email_empresa = 'correo dominio empresa';
        $emailempresa_password = 'Pandora19@5';
        $unidad_anizativa = 'Ruta Unidad';
        $codper = '00000001';
        // Datos del nuevo usuario
        $data = [
            'name' => [
                'familyName' => ucwords($apellidos),
                'givenName' => ucwords($nombres),
                'displayName' => ucwords($nombres_apellidos)
            ],
            'password' => $emailupch_password,
            'primaryEmail' => strtolower($email_empresa),
            'UnitPath' => $unidad_anizativa,
            'recoveryEmail' => $email,
            'changePasswordAtNextLogin' => true,
            'customSchemas' => [
            'EmployeeInfo' => [
            'EmployeeID' => '71313938'
                ]
            ],
            'Employee ID' => $codper,
            'Departamento' => 'OUTI'
            
        ];
          
        // Convertir los datos a JSON
        $jsonData = json_encode($data);

        // Configurar cURL para la solicitud POST
        $url = '';
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_HTTPHEADER, [
            'Authorization: Bearer ' . $accessToken,
            'Content-Type: application/json'
        ]);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

        // Enviar la solicitud y manejar la respuesta
        $response = curl_exec($ch);

        if (curl_errno($ch)) {
            echo 'Error en la solicitud: ' . curl_error($ch);
        } else {
            $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
            if ($httpCode == 200 || $httpCode == 201) {
                echo "Usuario creado exitosamente: " . json_encode(json_decode($response), JSON_PRETTY_PRINT);
            } else {
                echo "Error en la solicitud: HTTP $httpCode\n";
                echo "Contenido del error: " . json_encode(json_decode($response), JSON_PRETTY_PRINT);
            }
        }

        curl_close($ch);
`
    ?>  

As you can see, I am using the Google API to create accounts, and I am generating them successfully, but it only generates custom schemas as long as I have created the schema. However, the employee information already exists, and that is what I want to register. Most recommendations suggest using custom schemas, but I would like to know what fields correspond to Work Address, Employee ID, Employee Type, and Department or how I could register them.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745637143a4637463.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信