Codeigniter and google api integration fail

I am trying to call google api from codeigniter. I have unzipped the google api php library in a directory named asset of the codeigniter root directory. I use the following code to create a user.

require_once 'assets/vendor/autoload.php';
$domain="xxxxxxx.com";

class Google_model extends CI_Model
{
    public function __construct()
    {
        parent::__construct();
    }

    function Create_User($dir,$Given_Name,$Family_Name,$User_Name,$Password)//create a user 
    {
        global $domain;
        $UserInstance = new Google_Service_Directory_User(); 
        $NameInstance = new Google_Service_Directory_UserName(); 

        $NameInstance -> setGivenName($Given_Name); 
        $NameInstance -> setFamilyName($Family_Name); 

        $UserInstance -> setName($NameInstance); 
        $UserInstance -> setHashFunction("MD5"); 
        $UserInstance -> setPrimaryEmail("$User_Name@$domain"); 
        $UserInstance -> setPassword(hash("md5", $Password)); 
        $Create_Error=1;
        try 
        { 
            $createUserResult = $dir -> users -> insert($UserInstance); 
            $Create_Error=0;
        } 
        catch (Google_IO_Exception $gioe) 
        { 
            $Create_Error=$gioe->getMessage(); 
        } 
        catch (Google_Service_Exception $gse) 
        { 
            $Create_Error=$gse->getMessage(); 
        } 
        return $Create_Error;
    }

    function Insert_User($First_Name,$Last_Name,$User_Name,$Password)
    {
        global $domain;
        $Error=0;

        $client = new Google_Client();
        $client->setAuthConfig('assets/auth/service_account.json');
        $client->useApplicationDefaultCredentials();
        $client->addScope('https://www.googleapis.com/auth/admin.directory.user');
        $email="admin@$domain";
        $client->setSubject($email);

        $dir = new Google_Service_Directory($client);
        $Error=self::Exist_user($dir,$User_Name);
        if(!$Error)
        {
            $Error=self::Create_User($dir,$First_Name,$Last_Name,$User_Name,$Password);
        }

        return $Error;
    }
}

When I use Insert_User routine to create a user, it fails after calling the function Create_User on the line

$createUserResult = $dir -> users -> insert($UserInstance);

with an error Severity: Error

Message: Call to undefined method Google_Service_Directory_User::toSimpleObject()

Filename: Service/Resource.php

Line Number: 108

Backtrace:

How can I fix this?


Source: stackoverflow-php