Search code examples
phppropertiesgoogle-drive-api

unable to delete a property (or appProperty) using php client in google drive object


Searching in the web and in Stack Overflow I didn't find post where the problem was solved

I've this code

        $params = array();
        $file = new Google_Service_Drive_DriveFile();
        $file->setProperties("myProp"=>null);
        $response = $driveService->files->update($fileid,$file,$params);

and has no effect... the property mantains its original value (set with the same method)


Solution

  • In this case, how about using Google_Model::NULL_VALUE? When this is reflected in your script, it becomes as follows.

    From:

    $file->setProperties("myProp"=>null);
    

    To:

    For properties

    $file->setProperties(['myProp'=>Google_Model::NULL_VALUE]);
    

    For appProperties

    $file->setAppProperties(['myProp'=>Google_Model::NULL_VALUE]);
    
    • When I tested this, I confirmed that properties (or appProperties) are removed.

    References: